﻿HmJS.$Import('core.core');

HmJS.register('core.element', function ($ns) {

	var document = window.document;

	// #region -- Slick.Parser --

	/*
	---
	name: Slick.Parser
	description: Standalone CSS3 Selector parser
	provides: Slick.Parser
	...
	*/

	; (function () {

		var parsed,
				separatorIndex,
				combinatorIndex,
				reversed,
				cache = {},
				reverseCache = {},
				reUnescape = /\\/g;

		var parse = function (expression, isReversed) {
			if (expression == null) { return null; }
			if (expression.Slick === true) { return expression; }
			expression = ('' + expression).replace(/^\s+|\s+$/g, '');
			reversed = !!isReversed;
			var currentCache = (reversed) ? reverseCache : cache;
			if (currentCache[expression]) {
				return currentCache[expression];
			}
			parsed = {
				Slick: true,
				expressions: [],
				raw: expression,
				reverse: function () {
					return parse(this.raw, true);
				}
			};
			separatorIndex = -1;
			while (expression != (expression = expression.replace(regexp, parser))) { ; }
			parsed.length = parsed.expressions.length;
			return currentCache[parsed.raw] = (reversed) ? reverse(parsed) : parsed;
		};

		var reverseCombinator = function (combinator) {
			if (combinator === '!') {
				return ' ';
			} else if (combinator === ' ') {
				return '!';
			} else if ((/^!/).test(combinator)) {
				return combinator.replace(/^!/, '');
			} else {
				return '!' + combinator;
			}
		};

		var reverse = function (expression) {
			var expressions = expression.expressions,
					i = 0, l1 = expressions.length;
			/**
			# 苦苦的苦瓜 
			# 2011-10-12
			# for循环改为while循环
			**/
			while (i < l1) {
				var exp = expressions[i++],
						last = { parts: [], tag: '*', combinator: reverseCombinator(exp[0].combinator) },
						j = 0, l2 = exp.length;

				while (j < l2) {
					var cexp = exp[j++];
					if (!cexp.reverseCombinator) {
						cexp.reverseCombinator = ' ';
					}
					cexp.combinator = cexp.reverseCombinator;
					delete cexp.reverseCombinator;
				}

				exp.reverse().push(last);
			}
			return expression;
		};

		var escapeRegExp = function (string) {// Credit: XRegExp 0.6.1 (c) 2007-2008 Steven Levithan <http://stevenlevithan.com/regex/xregexp/> MIT License
			return string.replace(/[-[\]{}()*+?.\\^$|,#\s]/g, function (match) {
				return '\\' + match;
			});
		};

		var regexp = new RegExp(
		/*
		#!/usr/bin/env ruby
		puts "\t\t" + DATA.read.gsub(/\(\?x\)|\s+#.*$|\s+|\\$|\\n/,'')
		__END__
		"(?x)^(?:\
		\\s* ( , ) \\s*               # Separator          \n\
		| \\s* ( <combinator>+ ) \\s*   # Combinator         \n\
		|      ( \\s+ )                 # CombinatorChildren \n\
		|      ( <unicode>+ | \\* )     # Tag                \n\
		| \\#  ( <unicode>+       )     # ID                 \n\
		| \\.  ( <unicode>+       )     # ClassName          \n\
		|                               # Attribute          \n\
		\\[  \
		\\s* (<unicode1>+)  (?:  \
		\\s* ([*^$!~|]?=)  (?:  \
		\\s* (?:\
		([\"']?)(.*?)\\9 \
		)\
		)  \
		)?  \\s*  \
		\\](?!\\]) \n\
		|   :+ ( <unicode>+ )(?:\
		\\( (?:\
		(?:([\"'])([^\\12]*)\\12)|((?:\\([^)]+\\)|[^()]*)+)\
		) \\)\
		)?\
		)"
		*/
		"^(?:\\s*(,)\\s*|\\s*(<combinator>+)\\s*|(\\s+)|(<unicode>+|\\*)|\\#(<unicode>+)|\\.(<unicode>+)|\\[\\s*(<unicode1>+)(?:\\s*([*^$!~|]?=)(?:\\s*(?:([\"']?)(.*?)\\9)))?\\s*\\](?!\\])|(:+)(<unicode>+)(?:\\((?:(?:([\"'])([^\\13]*)\\13)|((?:\\([^)]+\\)|[^()]*)+))\\))?)"
		.replace(/<combinator>/, '[' + escapeRegExp(">+~`!@$%^&={}\\;</") + ']')
		.replace(/<unicode>/g, '(?:[\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])')
		.replace(/<unicode1>/g, '(?:[:\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])')
		);

		function parser(
		rawMatch,

		separator,
		combinator,
		combinatorChildren,

		tagName,
		id,
		className,

		attributeKey,
		attributeOperator,
		attributeQuote,
		attributeValue,

		pseudoMarker,
		pseudoClass,
		pseudoQuote,
		pseudoClassQuotedValue,
		pseudoClassValue) {
			if (separator || separatorIndex === -1) {
				parsed.expressions[++separatorIndex] = [];
				combinatorIndex = -1;
				if (separator) { return ''; }
			}

			if (combinator || combinatorChildren || combinatorIndex === -1) {
				combinator = combinator || ' ';
				var currentSeparator = parsed.expressions[separatorIndex];
				if (reversed && currentSeparator[combinatorIndex]) {
					currentSeparator[combinatorIndex].reverseCombinator = reverseCombinator(combinator);
				}
				currentSeparator[++combinatorIndex] = { combinator: combinator, tag: '*' };
			}

			var currentParsed = parsed.expressions[separatorIndex][combinatorIndex];

			if (tagName) {
				currentParsed.tag = tagName.replace(reUnescape, '');
			} else if (id) {
				currentParsed.id = id.replace(reUnescape, '');
			} else if (className) {
				className = className.replace(reUnescape, '');
				if (!currentParsed.classList) {
					currentParsed.classList = [];
				}
				if (!currentParsed.classes) {
					currentParsed.classes = [];
				}
				currentParsed.classList.push(className);
				currentParsed.classes.push({
					value: className,
					regexp: new RegExp('(^|\\s)' + escapeRegExp(className) + '(\\s|$)')
				});

			} else if (pseudoClass) {
				pseudoClassValue = pseudoClassValue || pseudoClassQuotedValue;
				pseudoClassValue = pseudoClassValue ? pseudoClassValue.replace(reUnescape, '') : null;

				if (!currentParsed.pseudos) {
					currentParsed.pseudos = [];
				}
				currentParsed.pseudos.push({
					key: pseudoClass.replace(reUnescape, ''),
					value: pseudoClassValue,
					type: pseudoMarker.length == 1 ? 'class' : 'element'
				});

			} else if (attributeKey) {
				attributeKey = attributeKey.replace(reUnescape, '');
				attributeValue = (attributeValue || '').replace(reUnescape, '');

				var test, regexp;

				switch (attributeOperator) {
					case '^=':
						regexp = new RegExp('^' + escapeRegExp(attributeValue));
						break;

					case '$=':
						regexp = new RegExp(escapeRegExp(attributeValue) + '$');
						break;
					case '~=':
						regexp = new RegExp('(^|\\s)' + escapeRegExp(attributeValue) + '(\\s|$)');
						break;

					case '|=':
						regexp = new RegExp('^' + escapeRegExp(attributeValue) + '(-|$)');
						break;

					case '=':
						test = function (value) {
							return attributeValue == value;
						};
						break;

					case '*=':
						test = function (value) {
							return value && value.indexOf(attributeValue) > -1;
						};
						break;

					case '!=':
						test = function (value) {
							return attributeValue != value;
						};
						break;

					default:
						test = function (value) {
							return !!value;
						};
				}

				if (attributeValue == '' && (/^[*$^]=$/).test(attributeOperator)) test = function () {
					return false;
				};

				if (!test) test = function (value) {
					return value && regexp.test(value);
				};

				if (!currentParsed.attributes) {
					currentParsed.attributes = [];
				}
				currentParsed.attributes.push({
					key: attributeKey,
					operator: attributeOperator,
					value: attributeValue,
					test: test
				});

			}

			return '';
		};

		// Slick NS

		var Slick = (this.Slick || {});

		Slick.parse = function (expression) {
			return parse(expression);
		};

		Slick.escapeRegExp = escapeRegExp;

		if (!this.Slick) { this.Slick = Slick; }

	}).apply(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);

	// #endregion

	// #region -- Slick.Finder --

	/*
	---
	name: Slick.Finder
	description: The new, superfast css selector engine.
	provides: Slick.Finder
	requires: Slick.Parser
	...
	*/

	; (function () {

		var local = {},
				featuresCache = {},
				toString = Object.prototype.toString;

		// Feature / Bug detection

		local.isNativeCode = function (fn) {
			return (/\{\s*\[native code\]\s*\}/).test('' + fn);
		};

		local.isXML = function (document) {
			return (!!document.xmlVersion) || (!!document.xml) || (toString.call(document) == '[object XMLDocument]')
					|| (document.nodeType == 9 && document.documentElement.nodeName != 'HTML');
		};

		local.setDocument = function (document) {

			// convert elements / window arguments to document. if document cannot be extrapolated, the function returns.
			var nodeType = document.nodeType;
			if (nodeType == 9) {
				; // document
			} else if (nodeType) {
				document = document.ownerDocument; // node
			} else if (document.navigator) {
				document = document.document; // window
			} else {
				return;
			}

			// check if it's the old document

			if (this.document === document) { return; }
			this.document = document;

			// check if we have done feature detection on this document before

			var root = document.documentElement,
					rootUid = this.getUIDXML(root),
					features = featuresCache[rootUid],
					feature;

			if (features) {
				for (feature in features) {
					this[feature] = features[feature];
				}
				return;
			}

			features = featuresCache[rootUid] = {};

			features.root = root;
			features.isXMLDocument = this.isXML(document);

			features.brokenStarGEBTN
				= features.starSelectsClosedQSA
				= features.idGetsName
				= features.brokenMixedCaseQSA
				= features.brokenGEBCN
				= features.brokenCheckedQSA
				= features.brokenEmptyAttributeQSA
				= features.isHTMLDocument
				= features.nativeMatchesSelector
				= false;

			/**
			# 苦苦的苦瓜
			# 2011-07-11
			# 合并成一个var声明
			**/
			var starSelectsClosed,
					starSelectsComments,
					brokenSecondClassNameGEBCN,
					cachedGetElementsByClassName,
					brokenFormAttributeGetter,

					selected,
					id = 'slick_uniqueid',
					testNode = document.createElement('div'),

					testRoot = document.body || document.getElementsByTagName('body')[0] || root;

			testRoot.appendChild(testNode);

			// on non-HTML documents innerHTML and getElementsById doesnt work properly
			try {
				testNode.innerHTML = '<a id="' + id + '"></a>';
				features.isHTMLDocument = !!document.getElementById(id);
			} catch (e) { };

			if (features.isHTMLDocument) {

				testNode.style.display = 'none';

				// IE returns comment nodes for getElementsByTagName('*') for some documents
				testNode.appendChild(document.createComment(''));
				starSelectsComments = (testNode.getElementsByTagName('*').length > 1);

				// IE returns closed nodes (EG:"</foo>") for getElementsByTagName('*') for some documents
				try {
					testNode.innerHTML = 'foo</foo>';
					selected = testNode.getElementsByTagName('*');
					starSelectsClosed = (selected && !!selected.length && selected[0].nodeName.charAt(0) == '/');
				} catch (e) { };

				features.brokenStarGEBTN = starSelectsComments || starSelectsClosed;

				// IE returns elements with the name instead of just id for getElementsById for some documents
				try {
					testNode.innerHTML = '<a name="' + id + '"></a><b id="' + id + '"></b>';
					features.idGetsName = document.getElementById(id) === testNode.firstChild;
				} catch (e) { };

				if (testNode.getElementsByClassName) {

					// Safari 3.2 getElementsByClassName caches results
					try {
						testNode.innerHTML = '<a class="f"></a><a class="b"></a>';
						testNode.getElementsByClassName('b').length;
						testNode.firstChild.className = 'b';
						cachedGetElementsByClassName = (testNode.getElementsByClassName('b').length != 2);
					} catch (e) { };

					// Opera 9.6 getElementsByClassName doesnt detects the class if its not the first one
					try {
						testNode.innerHTML = '<a class="a"></a><a class="f b a"></a>';
						brokenSecondClassNameGEBCN = (testNode.getElementsByClassName('a').length != 2);
					} catch (e) { };

					features.brokenGEBCN = cachedGetElementsByClassName || brokenSecondClassNameGEBCN;
				}

				if (testNode.querySelectorAll) {
					// IE 8 returns closed nodes (EG:"</foo>") for querySelectorAll('*') for some documents
					try {
						testNode.innerHTML = 'foo</foo>';
						selected = testNode.querySelectorAll('*');
						features.starSelectsClosedQSA = (selected && !!selected.length && selected[0].nodeName.charAt(0) == '/');
					} catch (e) { };

					// Safari 3.2 querySelectorAll doesnt work with mixedcase on quirksmode
					try {
						testNode.innerHTML = '<a class="MiX"></a>';
						features.brokenMixedCaseQSA = !testNode.querySelectorAll('.MiX').length;
					} catch (e) { };

					// Webkit and Opera dont return selected options on querySelectorAll
					try {
						testNode.innerHTML = '<select><option selected="selected">a</option></select>';
						features.brokenCheckedQSA = (testNode.querySelectorAll(':checked').length == 0);
					} catch (e) { };

					// IE returns incorrect results for attr[*^$]="" selectors on querySelectorAll
					try {
						testNode.innerHTML = '<a class=""></a>';
						features.brokenEmptyAttributeQSA = (testNode.querySelectorAll('[class*=""]').length != 0);
					} catch (e) { };

				}

				// IE6-7, if a form has an input of id x, form.getAttribute(x) returns a reference to the input
				try {
					testNode.innerHTML = '<form action="s"><input id="action"/></form>';
					brokenFormAttributeGetter = (testNode.firstChild.getAttribute('action') != 's');
				} catch (e) { };

				// native matchesSelector function

				features.nativeMatchesSelector = root.matchesSelector || /*root.msMatchesSelector ||*/root.mozMatchesSelector || root.webkitMatchesSelector;
				if (features.nativeMatchesSelector) {
					try {
						// if matchesSelector trows errors on incorrect sintaxes we can use it
						features.nativeMatchesSelector.call(root, ':slick');
						features.nativeMatchesSelector = null;
					} catch (e) { };
				}
			}

			try {
				root.slick_expando = 1;
				delete root.slick_expando;
				features.getUID = this.getUIDHTML;
			} catch (e) {
				features.getUID = this.getUIDXML;
			}

			testRoot.removeChild(testNode);
			testNode = selected = testRoot = null;

			// getAttribute

			features.getAttribute = (features.isHTMLDocument && brokenFormAttributeGetter) ? function (node, name) {
				var method = this.attributeGetters[name];
				if (method) {
					return method.call(node);
				}
				var attributeNode = node.getAttributeNode(name);
				return (attributeNode) ? attributeNode.nodeValue : null;
			} : function (node, name) {
				var method = this.attributeGetters[name];
				return (method) ? method.call(node) : node.getAttribute(name);
			};

			// hasAttribute

			features.hasAttribute = (root && this.isNativeCode(root.hasAttribute)) ? function (node, attribute) {
				return node.hasAttribute(attribute);
			} : function (node, attribute) {
				node = node.getAttributeNode(attribute);
				return !!(node && (node.specified || node.nodeValue));
			};

			// contains
			// FIXME: Add specs: local.contains should be different for xml and html documents?
			features.contains = (root && this.isNativeCode(root.contains)) ? function (context, node) {
				return context.contains(node);
			} : (root && root.compareDocumentPosition) ? function (context, node) {
				return context === node || !!(context.compareDocumentPosition(node) & 16);
			} : function (context, node) {
				if (node) {
					do {
						if (node === context) { return true; }
					} while ((node = node.parentNode));
				}
				return false;
			};

			// document order sorting
			// credits to Sizzle (http://sizzlejs.com/)

			features.documentSorter = (root.compareDocumentPosition) ? function (a, b) {
				if (!a.compareDocumentPosition || !b.compareDocumentPosition) {
					return 0;
				}
				return a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1;
			} : ('sourceIndex' in root) ? function (a, b) {
				if (!a.sourceIndex || !b.sourceIndex) {
					return 0;
				}
				return a.sourceIndex - b.sourceIndex;
			} : (document.createRange) ? function (a, b) {
				if (!a.ownerDocument || !b.ownerDocument) {
					return 0;
				}
				var aRange = a.ownerDocument.createRange(),
						bRange = b.ownerDocument.createRange();
				aRange.setStart(a, 0);
				aRange.setEnd(a, 0);
				bRange.setStart(b, 0);
				bRange.setEnd(b, 0);
				return aRange.compareBoundaryPoints(Range.START_TO_END, bRange);
			} : null;

			root = null;

			for (feature in features) {
				this[feature] = features[feature];
			}
		};

		// Main Method

		var reSimpleSelector = /^([#.]?)((?:[\w-]+|\*))$/,
				reEmptyAttribute = /\[.+[*$^]=(?:""|'')?\]/,
				qsaFailExpCache = {};

		local.search = function (context, expression, append, first) {

			var found = this.found = (first) ? null : (append || []);

			if (!context) {
				return found;
			} else if (context.navigator) {
				context = context.document; // Convert the node from a window to a document
			} else if (!context.nodeType) {
				return found;
			}

			// setup

			var parsed, i,
					uniques = this.uniques = {},
					hasOthers = !!(append && append.length),
					contextIsDocument = (context.nodeType == 9);

			if (this.document !== (contextIsDocument ? context : context.ownerDocument)) {
				this.setDocument(context);
			}

			// avoid duplicating items already in the append array
			if (hasOthers) {
				/**
				# 苦苦的苦瓜 
				# 2011-10-12
				# for循环改为while循环
				**/
				i = found.length;
				while (i--) {
					uniques[this.getUID(found[i])] = true;
				}
			}

			// expression checks

			if (typeof expression == 'string') { // expression is a string

				/*<simple-selectors-override>*/
				var simpleSelector = expression.match(reSimpleSelector);
				simpleSelectors: if (simpleSelector) {

					var symbol = simpleSelector[1],
							name = simpleSelector[2],
							node, nodes;

					if (!symbol) {
						if (name == '*' && this.brokenStarGEBTN) {
							break simpleSelectors;
						}
						nodes = context.getElementsByTagName(name);
						if (first) {
							return nodes[0] || null;
						}
						/**
						# 苦苦的苦瓜 
						# 2011-10-12
						# for循环改为while循环
						# for (i = 0; node = nodes[i++]; ) {
						**/
						i = 0;
						while (node = nodes[i++]) {
							if (!(hasOthers && uniques[this.getUID(node)])) {
								found.push(node);
							}
						}
					} else if (symbol == '#') {
						if (!this.isHTMLDocument || !contextIsDocument) {
							break simpleSelectors;
						}
						node = context.getElementById(name);
						if (!node) {
							return found;
						}
						if (this.idGetsName && node.getAttributeNode('id').nodeValue != name) {
							break simpleSelectors;
						}
						if (first) {
							return node || null;
						}
						if (!(hasOthers && uniques[this.getUID(node)])) {
							found.push(node);
						}
					} else if (symbol == '.') {
						if (!this.isHTMLDocument || ((!context.getElementsByClassName || this.brokenGEBCN) && context.querySelectorAll)) {
							break simpleSelectors;
						}
						if (context.getElementsByClassName && !this.brokenGEBCN) {
							nodes = context.getElementsByClassName(name);
							if (first) {
								return nodes[0] || null;
							}
							/**
							# 苦苦的苦瓜 
							# 2011-10-12
							# for循环改为while循环
							# for (i = 0; node = nodes[i++]; ) {
							**/
							i = 0;
							while (node = nodes[i++]) {
								if (!(hasOthers && uniques[this.getUID(node)])) {
									found.push(node);
								}
							}
						} else {
							var matchClass = new RegExp('(^|\\s)' + Slick.escapeRegExp(name) + '(\\s|$)');
							nodes = context.getElementsByTagName('*');
							/**
							# 苦苦的苦瓜 
							# 2011-10-12
							# for循环改为while循环
							# for (i = 0; node = nodes[i++]; ) {
							**/
							i = 0;
							while (node = nodes[i++]) {
								className = node.className;
								if (!(className && matchClass.test(className))) {
									continue;
								}
								if (first) { return node; }
								if (!(hasOthers && uniques[this.getUID(node)])) {
									found.push(node);
								}
							}
						}
					}

					if (hasOthers) { this.sort(found); }
					return (first) ? null : found;

				}
				/*</simple-selectors-override>*/

				/*<query-selector-override>*/
				querySelector: if (context.querySelectorAll) {

					if (!this.isHTMLDocument
				|| qsaFailExpCache[expression]
					//TODO: only skip when expression is actually mixed case
				|| this.brokenMixedCaseQSA
				|| (this.brokenCheckedQSA && expression.indexOf(':checked') > -1)
				|| (this.brokenEmptyAttributeQSA && reEmptyAttribute.test(expression))
				|| (!contextIsDocument //Abort when !contextIsDocument and...
					//  there are multiple expressions in the selector
					//  since we currently only fix non-document rooted QSA for single expression selectors
					&& expression.indexOf(',') > -1)
				|| Slick.disableQSA) {
						break querySelector;
					}

					var _expression = expression,
							_context = context;
					if (!contextIsDocument) {
						// non-document rooted QSA
						// credits to Andrew Dupont
						var currentId = _context.getAttribute('id'),
								slickid = 'slickid__';
						_context.setAttribute('id', slickid);
						_expression = '#' + slickid + ' ' + _expression;
						context = _context.parentNode;
					}

					try {
						if (first) {
							return context.querySelector(_expression) || null;
						} else {
							nodes = context.querySelectorAll(_expression);
						}
					} catch (e) {
						qsaFailExpCache[expression] = 1;
						break querySelector;
					} finally {
						if (!contextIsDocument) {
							if (currentId) {
								_context.setAttribute('id', currentId);
							} else {
								_context.removeAttribute('id');
							}
							context = _context;
						}
					}

					if (this.starSelectsClosedQSA) {
						/**
						# 苦苦的苦瓜 
						# 2011-10-12
						# for循环改为while循环
						# for (i = 0; node = nodes[i++]; ) {
						**/
						i = 0;
						while (node = nodes[i++]) {
							if (node.nodeName > '@' && !(hasOthers && uniques[this.getUID(node)])) {
								found.push(node);
							}
						}
					} else {
						/**
						# 苦苦的苦瓜 
						# 2011-10-12
						# for循环改为while循环
						# for (i = 0; node = nodes[i++]; ) {
						**/
						i = 0;
						while (node = nodes[i++]) {
							if (!(hasOthers && uniques[this.getUID(node)])) {
								found.push(node);
							}
						}
					}

					if (hasOthers) { this.sort(found); }
					return found;

				}
				/*</query-selector-override>*/

				parsed = this.Slick.parse(expression);
				if (!parsed.length) {
					return found;
				}
			} else if (expression == null) { // there is no expression
				return found;
			} else if (expression.Slick) { // expression is a parsed Slick object
				parsed = expression;
			} else if (this.contains(context.documentElement || context, expression)) { // expression is a node
				(found) ? found.push(expression) : found = expression;
				return found;
			} else { // other junk
				return found;
			}

			/*<pseudo-selectors>*//*<nth-pseudo-selectors>*/

			// cache elements for the nth selectors

			this.posNTH = {};
			this.posNTHLast = {};
			this.posNTHType = {};
			this.posNTHTypeLast = {};

			/*</nth-pseudo-selectors>*//*</pseudo-selectors>*/

			// if append is null and there is only a single selector with one expression use pushArray, else use pushUID
			this.push = (!hasOthers && (first || (parsed.length == 1 && parsed.expressions[0].length == 1))) ? this.pushArray : this.pushUID;

			if (found == null) { found = []; }

			// default engine

			/**
			# 苦苦的苦瓜
			# 2011-07-17
			# 三个var声明合并为一个
			**/
			var j, m, n,
					combinator, tag, id, classList, classes, attributes, pseudos,
					currentItems, currentExpression, currentBit, lastBit, expressions = parsed.expressions;

			search: for (i = 0; (currentExpression = expressions[i]); i++) {
				for (j = 0; (currentBit = currentExpression[j]); j++) {

					combinator = 'combinator:' + currentBit.combinator;
					if (!this[combinator]) { continue search; }

					tag = (this.isXMLDocument) ? currentBit.tag : currentBit.tag.toUpperCase();
					id = currentBit.id;
					classList = currentBit.classList;
					classes = currentBit.classes;
					attributes = currentBit.attributes;
					pseudos = currentBit.pseudos;
					lastBit = (j === (currentExpression.length - 1));

					this.bitUniques = {};

					if (lastBit) {
						this.uniques = uniques;
						this.found = found;
					} else {
						this.uniques = {};
						this.found = [];
					}

					if (j === 0) {
						this[combinator](context, tag, id, classes, attributes, pseudos, classList);
						if (first && lastBit && found.length) { break search; }
					} else {
						if (first && lastBit) {
							for (m = 0, n = currentItems.length; m < n; m++) {
								this[combinator](currentItems[m], tag, id, classes, attributes, pseudos, classList);
								if (found.length) { break search; }
							}
						} else {
							for (m = 0, n = currentItems.length; m < n; m++) {
								this[combinator](currentItems[m], tag, id, classes, attributes, pseudos, classList);
							}
						}
					}

					currentItems = this.found;
				}
			}

			// should sort if there are nodes in append and if you pass multiple expressions.
			if (hasOthers || (parsed.expressions.length > 1)) { this.sort(found); }

			return (first) ? (found[0] || null) : found;
		};

		// Utils

		local.uidx = 1;
		local.uidk = 'slick-uniqueid';

		local.getUIDXML = function (node) {
			var uid = node.getAttribute(this.uidk);
			if (!uid) {
				uid = this.uidx++;
				node.setAttribute(this.uidk, uid);
			}
			return uid;
		};

		local.getUIDHTML = function (node) {
			return node.uniqueNumber || (node.uniqueNumber = this.uidx++);
		};

		// sort based on the setDocument documentSorter method.

		local.sort = function (results) {
			if (!this.documentSorter) { return results; }
			results.sort(this.documentSorter);
			return results;
		};

		/*<pseudo-selectors>*//*<nth-pseudo-selectors>*/

		local.cacheNTH = {};

		local.matchNTH = /^([+-]?\d*)?([a-z]+)?([+-]\d+)?$/;

		local.parseNTHArgument = function (argument) {
			var parsed = argument.match(this.matchNTH);
			if (!parsed) { return false; }
			var special = parsed[2] || false;
			var a = parsed[1] || 1;
			if (a == '-') { a = -1; }
			var b = +parsed[3] || 0;
			parsed =
			(special == 'n') ? { a: a, b: b} :
			(special == 'odd') ? { a: 2, b: 1} :
			(special == 'even') ? { a: 2, b: 0} : { a: 0, b: a };

			return (this.cacheNTH[argument] = parsed);
		};

		local.createNTHPseudo = function (child, sibling, positions, ofType) {
			return function (node, argument) {
				var uid = this.getUID(node);
				if (!this[positions][uid]) {
					var parent = node.parentNode;
					if (!parent) { return false; }
					var el = parent[child],
						count = 1;
					if (ofType) {
						var nodeName = node.nodeName;
						do {
							if (el.nodeName != nodeName) { continue; }
							this[positions][this.getUID(el)] = count++;
						} while ((el = el[sibling]));
					} else {
						do {
							if (el.nodeType != 1) { continue; }
							this[positions][this.getUID(el)] = count++;
						} while ((el = el[sibling]));
					}
				}
				argument = argument || 'n';
				var parsed = this.cacheNTH[argument] || this.parseNTHArgument(argument);
				if (!parsed) { return false; }
				var a = parsed.a,
						b = parsed.b,
						pos = this[positions][uid];
				if (a == 0) { return b == pos; }
				if (a > 0) {
					if (pos < b) { return false; }
				} else {
					if (b < pos) { return false; }
				}
				return ((pos - b) % a) == 0;
			};
		};

		/*</nth-pseudo-selectors>*//*</pseudo-selectors>*/

		local.pushArray = function (node, tag, id, classes, attributes, pseudos) {
			if (this.matchSelector(node, tag, id, classes, attributes, pseudos)) {
				this.found.push(node);
			}
		};

		local.pushUID = function (node, tag, id, classes, attributes, pseudos) {
			var uid = this.getUID(node);
			if (!this.uniques[uid] && this.matchSelector(node, tag, id, classes, attributes, pseudos)) {
				this.uniques[uid] = true;
				this.found.push(node);
			}
		};

		local.matchNode = function (node, selector) {
			if (this.isHTMLDocument && this.nativeMatchesSelector) {
				try {
					return this.nativeMatchesSelector.call(node, selector.replace(/\[([^=]+)=\s*([^'"\]]+?)\s*\]/g, '[$1="$2"]'));
				} catch (matchError) { }
			}

			var parsed = this.Slick.parse(selector);
			if (!parsed) { return true; }

			// simple (single) selectors
			var expressions = parsed.expressions, simpleExpCounter = 0, i;
			for (i = 0; (currentExpression = expressions[i]); i++) {
				if (currentExpression.length == 1) {
					var exp = currentExpression[0];
					if (this.matchSelector(node, (this.isXMLDocument) ? exp.tag : exp.tag.toUpperCase(), exp.id, exp.classes, exp.attributes, exp.pseudos)) {
						return true;
					}
					simpleExpCounter++;
				}
			}

			if (simpleExpCounter == parsed.length) { return false; }

			var nodes = this.search(this.document, parsed),
					item;
			/**
			# 苦苦的苦瓜 
			# 2011-10-12
			# for循环改为while循环
			# for (i = 0; item = nodes[i++]; ) {
			**/
			i = 0;
			while (item = nodes[i++]) {
				if (item === node) { return true; }
			}
			return false;
		};

		local.matchPseudo = function (node, name, argument) {
			var pseudoName = 'pseudo:' + name;
			if (this[pseudoName]) {
				return this[pseudoName](node, argument);
			}
			var attribute = this.getAttribute(node, name);
			return (argument) ? argument == attribute : !!attribute;
		};

		local.matchSelector = function (node, tag, id, classes, attributes, pseudos) {
			if (tag) {
				var nodeName = (this.isXMLDocument) ? node.nodeName : node.nodeName.toUpperCase();
				if (tag == '*') {
					if (nodeName < '@') { return false; } // Fix for comment nodes and closed nodes
				} else {
					if (nodeName != tag) { return false; }
				}
			}

			if (id && node.getAttribute('id') != id) {
				return false;
			}

			var i, part, cls;
			if (classes) {
				/**
				# 苦苦的苦瓜 
				# 2011-10-12
				# for循环改为while循环
				# for (i = classes.length; i--; ) {
				**/
				i = classes.length;
				while (i--) {
					cls = node.getAttribute('class') || node.className;
					if (!(cls && classes[i].regexp.test(cls))) {
						return false;
					}
				}
			}
			if (attributes) {
				/**
				# 苦苦的苦瓜 
				# 2011-10-12
				# for循环改为while循环
				# for (i = attributes.length; i--; ) {
				**/
				i = attributes.length;
				while (i--) {
					part = attributes[i];
					if (part.operator ? !part.test(this.getAttribute(node, part.key)) : !this.hasAttribute(node, part.key)) {
						return false;
					}
				}
			}
			if (pseudos) {
				/**
				# 苦苦的苦瓜 
				# 2011-10-12
				# for循环改为while循环
				# for (i = pseudos.length; i--; ) {
				**/
				i = pseudos.length;
				while (i--) {
					part = pseudos[i];
					if (!this.matchPseudo(node, part.key, part.value)) {
						return false;
					}
				}
			}
			return true;
		};

		var combinators = {

			' ': function (node, tag, id, classes, attributes, pseudos, classList) { // all child nodes, any level

				var i, item, children;

				if (this.isHTMLDocument) {
					getById: if (id) {
						item = this.document.getElementById(id);
						if ((!item && node.all) || (this.idGetsName && item && item.getAttributeNode('id').nodeValue != id)) {
							// all[id] returns all the elements with that name or id inside node
							// if theres just one it will return the element, else it will be a collection
							children = node.all[id];
							if (!children) { return; }
							if (!children[0]) { children = [children]; }
							/**
							# 苦苦的苦瓜 
							# 2011-10-12
							# for循环改为while循环
							# for (i = 0; item = children[i++]; ) {
							**/
							i = 0;
							while (item = children[i++]) {
								var idNode = item.getAttributeNode('id');
								if (idNode && idNode.nodeValue == id) {
									this.push(item, tag, null, classes, attributes, pseudos);
									break;
								}
							}
							return;
						}
						if (!item) {
							// if the context is in the dom we return, else we will try GEBTN, breaking the getById label
							if (this.contains(this.root, node)) {
								return;
							} else {
								break getById;
							}
						} else if (this.document !== node && !this.contains(node, item)) {
							return;
						}
						this.push(item, tag, null, classes, attributes, pseudos);
						return;
					}
					getByClass: if (classes && node.getElementsByClassName && !this.brokenGEBCN) {
						children = node.getElementsByClassName(classList.join(' '));
						if (!(children && children.length)) {
							break getByClass;
						}
						/**
						# 苦苦的苦瓜 
						# 2011-10-12
						# for循环改为while循环
						# for (i = 0; item = children[i++]; ) {
						**/
						i = 0;
						while (item = children[i++]) {
							this.push(item, tag, id, null, attributes, pseudos);
						}
						return;
					}
				}
				getByTag:
				{
					children = node.getElementsByTagName(tag);
					if (!(children && children.length)) {
						break getByTag;
					}
					if (!this.brokenStarGEBTN) {
						tag = null;
					}
					/**
					# 苦苦的苦瓜 
					# 2011-10-12
					# for循环改为while循环
					# for (i = 0; item = children[i++]; ) {
					**/
					i = 0;
					while (item = children[i++]) {
						this.push(item, tag, id, classes, attributes, pseudos);
					}
				}
			},

			'>': function (node, tag, id, classes, attributes, pseudos) { // direct children
				if ((node = node.firstChild)) {
					do {
						if (node.nodeType == 1) {
							this.push(node, tag, id, classes, attributes, pseudos);
						}
					} while ((node = node.nextSibling));
				}
			},

			'+': function (node, tag, id, classes, attributes, pseudos) { // next sibling
				while ((node = node.nextSibling)) {
					if (node.nodeType == 1) {
						this.push(node, tag, id, classes, attributes, pseudos);
						break;
					}
				}
			},

			'^': function (node, tag, id, classes, attributes, pseudos) { // first child
				node = node.firstChild;
				if (node) {
					if (node.nodeType == 1) {
						this.push(node, tag, id, classes, attributes, pseudos);
					} else {
						this['combinator:+'](node, tag, id, classes, attributes, pseudos);
					}
				}
			},

			'~': function (node, tag, id, classes, attributes, pseudos) { // next siblings
				while ((node = node.nextSibling)) {
					if (node.nodeType != 1) { continue; }
					var uid = this.getUID(node);
					if (this.bitUniques[uid]) { break; }
					this.bitUniques[uid] = true;
					this.push(node, tag, id, classes, attributes, pseudos);
				}
			},

			'++': function (node, tag, id, classes, attributes, pseudos) { // next sibling and previous sibling
				this['combinator:+'](node, tag, id, classes, attributes, pseudos);
				this['combinator:!+'](node, tag, id, classes, attributes, pseudos);
			},

			'~~': function (node, tag, id, classes, attributes, pseudos) { // next siblings and previous siblings
				this['combinator:~'](node, tag, id, classes, attributes, pseudos);
				this['combinator:!~'](node, tag, id, classes, attributes, pseudos);
			},

			'!': function (node, tag, id, classes, attributes, pseudos) { // all parent nodes up to document
				while ((node = node.parentNode)) {
					if (node !== this.document) {
						this.push(node, tag, id, classes, attributes, pseudos);
					}
				}
			},

			'!>': function (node, tag, id, classes, attributes, pseudos) { // direct parent (one level)
				node = node.parentNode;
				if (node !== this.document) {
					this.push(node, tag, id, classes, attributes, pseudos);
				}
			},

			'!+': function (node, tag, id, classes, attributes, pseudos) { // previous sibling
				while ((node = node.previousSibling)) {
					if (node.nodeType == 1) {
						this.push(node, tag, id, classes, attributes, pseudos);
						break;
					}
				}
			},

			'!^': function (node, tag, id, classes, attributes, pseudos) { // last child
				node = node.lastChild;
				if (node) {
					if (node.nodeType == 1) {
						this.push(node, tag, id, classes, attributes, pseudos);
					} else {
						this['combinator:!+'](node, tag, id, classes, attributes, pseudos);
					}
				}
			},

			'!~': function (node, tag, id, classes, attributes, pseudos) { // previous siblings
				while ((node = node.previousSibling)) {
					if (node.nodeType != 1) { continue; }
					var uid = this.getUID(node);
					if (this.bitUniques[uid]) { break; }
					this.bitUniques[uid] = true;
					this.push(node, tag, id, classes, attributes, pseudos);
				}
			}

		};

		for (var c in combinators) {
			local['combinator:' + c] = combinators[c];
		}

		var pseudos = {

			/*<pseudo-selectors>*/

			'empty': function (node) {
				var child = node.firstChild;
				return !(child && child.nodeType == 1) && !(node.innerText || node.textContent || '').length;
			},

			'not': function (node, expression) {
				return !this.matchNode(node, expression);
			},

			'contains': function (node, text) {
				return (node.innerText || node.textContent || '').indexOf(text) > -1;
			},

			'first-child': function (node) {
				while ((node = node.previousSibling)) {
					if (node.nodeType == 1) { return false; }
				}
				return true;
			},

			'last-child': function (node) {
				while ((node = node.nextSibling)) {
					if (node.nodeType == 1) { return false; }
				}
				return true;
			},

			'only-child': function (node) {
				var prev = node;
				while ((prev = prev.previousSibling)) {
					if (prev.nodeType == 1) { return false; }
				}
				var next = node;
				while ((next = next.nextSibling)) {
					if (next.nodeType == 1) { return false; }
				}
				return true;
			},

			/*<nth-pseudo-selectors>*/

			'nth-child': local.createNTHPseudo('firstChild', 'nextSibling', 'posNTH'),

			'nth-last-child': local.createNTHPseudo('lastChild', 'previousSibling', 'posNTHLast'),

			'nth-of-type': local.createNTHPseudo('firstChild', 'nextSibling', 'posNTHType', true),

			'nth-last-of-type': local.createNTHPseudo('lastChild', 'previousSibling', 'posNTHTypeLast', true),

			'index': function (node, index) {
				return this['pseudo:nth-child'](node, '' + index + 1);
			},

			'even': function (node) {
				return this['pseudo:nth-child'](node, '2n');
			},

			'odd': function (node) {
				return this['pseudo:nth-child'](node, '2n+1');
			},

			/*</nth-pseudo-selectors>*/

			/*<of-type-pseudo-selectors>*/

			'first-of-type': function (node) {
				var nodeName = node.nodeName;
				while ((node = node.previousSibling)) {
					if (node.nodeName == nodeName) { return false; }
				}
				return true;
			},

			'last-of-type': function (node) {
				var nodeName = node.nodeName;
				while ((node = node.nextSibling)) {
					if (node.nodeName == nodeName) { return false; }
				}
				return true;
			},

			'only-of-type': function (node) {
				var prev = node, nodeName = node.nodeName;
				while ((prev = prev.previousSibling)) {
					if (prev.nodeName == nodeName) { return false; }
				}
				var next = node;
				while ((next = next.nextSibling)) {
					if (next.nodeName == nodeName) { return false; }
				}
				return true;
			},

			/*</of-type-pseudo-selectors>*/

			// custom pseudos

			'enabled': function (node) {
				return !node.disabled;
			},

			'disabled': function (node) {
				return node.disabled;
			},

			'checked': function (node) {
				return node.checked || node.selected;
			},

			'focus': function (node) {
				return this.isHTMLDocument && this.document.activeElement === node && (node.href || node.type || this.hasAttribute(node, 'tabindex'));
			},

			'root': function (node) {
				return (node === this.root);
			},

			'selected': function (node) {
				return node.selected;
			}

			/*</pseudo-selectors>*/
		};

		for (var p in pseudos) {
			local['pseudo:' + p] = pseudos[p];
		}

		// attributes methods

		var attributeGetters = local.attributeGetters = {

			'class': function () {
				return this.getAttribute('class') || this.className;
			},

			'for': function () {
				return ('htmlFor' in this) ? this.htmlFor : this.getAttribute('for');
			},

			'href': function () {
				return ('href' in this) ? this.getAttribute('href', 2) : this.getAttribute('href');
			},

			'style': function () {
				return (this.style) ? this.style.cssText : this.getAttribute('style');
			},

			'tabindex': function () {
				var attributeNode = this.getAttributeNode('tabindex');
				return (attributeNode && attributeNode.specified) ? attributeNode.nodeValue : null;
			},

			'type': function () {
				return this.getAttribute('type');
			},

			'maxlength': function () {
				var attributeNode = this.getAttributeNode('maxLength');
				return (attributeNode && attributeNode.specified) ? attributeNode.nodeValue : null;
			}

		};

		attributeGetters.MAXLENGTH = attributeGetters.maxLength = attributeGetters.maxlength;

		// Slick

		var Slick = local.Slick = (this.Slick || {});

		Slick.version = '1.1.6';

		// Slick finder

		Slick.search = function (context, expression, append) {
			return local.search(context, expression, append);
		};

		Slick.find = function (context, expression) {
			return local.search(context, expression, null, true);
		};

		// Slick containment checker

		Slick.contains = function (container, node) {
			local.setDocument(container);
			return local.contains(container, node);
		};

		// Slick attribute getter

		Slick.getAttribute = function (node, name) {
			local.setDocument(node);
			return local.getAttribute(node, name);
		};

		Slick.hasAttribute = function (node, name) {
			local.setDocument(node);
			return local.hasAttribute(node, name);
		};

		// Slick matcher

		Slick.match = function (node, selector) {
			if (!(node && selector)) { return false; }
			if (!selector || selector === node) { return true; }
			local.setDocument(node);
			return local.matchNode(node, selector);
		};

		// Slick attribute accessor

		Slick.defineAttributeGetter = function (name, fn) {
			local.attributeGetters[name] = fn;
			return this;
		};

		Slick.lookupAttributeGetter = function (name) {
			return local.attributeGetters[name];
		};

		// Slick pseudo accessor

		Slick.definePseudo = function (name, fn) {
			local['pseudo:' + name] = function (node, argument) {
				return fn.call(node, argument);
			};
			return this;
		};

		Slick.lookupPseudo = function (name) {
			var pseudo = local['pseudo:' + name];
			if (pseudo) {
				return function (argument) {
					return pseudo.call(this, argument);
				};
			}
			return null;
		};

		// Slick overrides accessor

		Slick.override = function (regexp, fn) {
			local.override(regexp, fn);
			return this;
		};

		Slick.isXML = local.isXML;

		Slick.uidOf = function (node) {
			return local.getUIDHTML(node);
		};

		if (!this.Slick) { this.Slick = Slick; }

	}).apply(/*<CommonJS>*/(typeof exports != 'undefined') ? exports : /*</CommonJS>*/this);

	// #endregion

	// #region -- Events.Pseudos --

	/**
	* name: Events.Pseudos
	* 
	* description: Adds the functionality to add pseudo events
	* 
	* authors:
	*   - Arian Stolwijk
	* 
	* requires: [Core/Class.Extras, Core/Slick.Parser, More/MooTools.More]
	* 
	* provides: [Events.Pseudos]
	**/

	(function () {

		Events.Pseudos = function (pseudos, addEvent, removeEvent) {

			var storeKey = '_monitorEvents:';

			var storageOf = function (object) {
				return {
					store: object.store ? function (key, value) {
						object.store(storeKey + key, value);
					} : function (key, value) {
						(object._monitorEvents || (object._monitorEvents = {}))[key] = value;
					},
					retrieve: object.retrieve ? function (key, dflt) {
						return object.retrieve(storeKey + key, dflt);
					} : function (key, dflt) {
						if (!object._monitorEvents) { return dflt; }
						return object._monitorEvents[key] || dflt;
					}
				};
			};

			var splitType = function (type) {
				if (type.indexOf(':') == -1 || !pseudos) { return null; }

				var parsed = Slick.parse(type).expressions[0][0],
						parsedPseudos = parsed.pseudos,
						l = parsedPseudos.length,
						splits = [];

				while (l--) {
					var pseudo = parsedPseudos[l].key,
							listener = pseudos[pseudo];
					if (listener != null) {
						splits.push({
							event: parsed.tag,
							value: parsedPseudos[l].value,
							pseudo: pseudo,
							original: type,
							listener: listener
						});
					}
				}
				return splits.length ? splits : null;
			};

			return {

				addEvent: function (type, fn, internal) {
					var split = splitType(type);
					if (!split) {
						return addEvent.call(this, type, fn, internal);
					}

					var storage = storageOf(this),
							events = storage.retrieve(type, []),
							eventType = split[0].event,
							args = Array.slice(arguments, 2),
							stack = fn,
							self = this;

					split.each(function (item) {
						var listener = item.listener,
								stackFn = stack;
						if (listener == false) {
							eventType += ':' + item.pseudo + '(' + item.value + ')';
						} else {
							stack = function () {
								listener.call(self, item, stackFn, arguments, stack);
							};
						}
					});

					events.include({ type: eventType, event: fn, monitor: stack });
					storage.store(type, events);

					if (type != eventType) {
						addEvent.apply(this, [type, fn].concat(args));
					}
					return addEvent.apply(this, [eventType, stack].concat(args));
				},

				removeEvent: function (type, fn) {
					var split = splitType(type);
					if (!split) {
						return removeEvent.call(this, type, fn);
					}

					var storage = storageOf(this),
							events = storage.retrieve(type);
					if (!events) { return this; }

					var args = Array.slice(arguments, 2);

					removeEvent.apply(this, [type, fn].concat(args));
					events.each(function (monitor, i) {
						if (!fn || monitor.event == fn) {
							removeEvent.apply(this, [monitor.type, monitor.monitor].concat(args));
						}
						delete events[i];
					}, this);

					storage.store(type, events);
					return this;
				}

			};

		};

		var pseudos = {

			once: function (split, fn, args, monitor) {
				fn.apply(this, args);
				this.removeEvent(split.event, monitor)
						.removeEvent(split.original, fn);
			},

			throttle: function (split, fn, args) {
				if (!fn._throttled) {
					fn.apply(this, args);
					fn._throttled = setTimeout(function () {
						fn._throttled = false;
					}, split.value || 250);
				}
			},

			pause: function (split, fn, args) {
				clearTimeout(fn._pause);
				fn._pause = fn.delay(split.value || 250, this, args);
			}

		};

		Events.definePseudo = function (key, listener) {
			pseudos[key] = listener;
			return this;
		};

		Events.lookupPseudo = function (key) {
			return pseudos[key];
		};

		var proto = Events.prototype;
		Events.implement(Events.Pseudos(pseudos, proto.addEvent, proto.removeEvent));

		['Request', 'Fx'].each(function (klass) {
			if (this[klass]) { this[klass].implement(Events.prototype); }
		});

	})();

	// #endregion

	// #region -- Element --

	/*
	---

	name: Element

	description: One of the most important items in MooTools. Contains the dollar function, the dollars function, and an handful of cross-browser, time-saver methods to let you easily work with HTML Elements.

	license: MIT-style license.

	requires: [Window, Document, Array, String, Function, Object, Number, Slick.Parser, Slick.Finder]

	provides: [Element, Elements, $, $$, Iframe, Selectors, Class.Occlude]

	...
	*/

	// #region - Element -

	/**
	* @method: constructor
	* @param element - (mixed) 创建的Element对象的实际DOM元素的标签名
	* @param properties - (object, optional) Calls the Single Argument version of Element:set with the properties object passed in.
	* @returns: (element) 一个新的MooTools扩展后的HTML元素
	* @description: 根据指定的元素类型创建新元素
	* @note: Because the element name is parsed as a CSS selector, colons in namespaced tags have to be escaped. So new Element('fb\:name) becomes <fb:name>.
	**/
	var Element = this.Element = function (tag, props) {
		var konstructor = Element.Constructors[tag],
				$_doc = document; // # 苦苦的苦瓜 2011-10-08
		if (konstructor) {
			return konstructor(props);
		}
		if (typeof tag != 'string') {
			return $_doc.id(tag).set(props);
		}

		if (!props) { props = {}; }

		if (!(/^[\w-]+$/).test(tag)) {
			var parsed = Slick.parse(tag).expressions[0][0];
			tag = (parsed.tag == '*') ? 'div' : parsed.tag;
			if (parsed.id && props.id == null) {
				props.id = parsed.id;
			}

			var attributes = parsed.attributes;
			if (attributes) {
				/**
				# 苦苦的苦瓜 
				# 2011-10-12
				# for循环改为while循环
				# for (var attr, i = 0, l = attributes.length; i < l; i++) {
				**/
				var attr, i = 0, l = attributes.length;
				while (i < l) {
					attr = attributes[i++];
					if (props[attr.key] != null) { continue; }

					if (attr.value != null && attr.operator == '=') {
						props[attr.key] = attr.value;
					} else if (!attr.value && !attr.operator) {
						props[attr.key] = true;
					}
				}
			}

			if (parsed.classList && props['class'] == null) {
				props['class'] = parsed.classList.join(' ');
			}
		}

		return $_doc.newElement(tag, props);
	};

	if (Browser.Element) {
		Element.prototype = Browser.Element.prototype;
	}

	new Type('Element', Element).mirror(function (name) {
		if (Array.prototype[name]) { return; }

		var obj = {};
		obj[name] = function () {
			var results = [],
					args = arguments,
					elements = true;
			for (var i = 0, l = this.length; i < l; i++) {
				var element = this[i],
						result = results[i] = element[name].apply(element, args);
				elements = (elements && typeOf(result) == 'element');
			}
			return (elements) ? new Elements(results) : results;
		};

		Elements.implement(obj);
	});

	if (!Browser.Element) {
		Element.parent = Object;

		Element.Prototype = { '$family': Function.from('element').hide() };

		Element.mirror(function (name, method) {
			Element.Prototype[name] = method;
		});
	}

	Element.Constructors = {};

	// #endregion

	// #region - IFrame -

	var IFrame = this.IFrame = new Type('IFrame', function () {
		var params = Array.link(arguments, {
			properties: Type.isObject,
			iframe: function (obj) {
				return (obj != null);
			}
		});

		var props = params.properties || {}, iframe;
		if (params.iframe) {
			iframe = document.id(params.iframe);
		}
		var onload = props.onload || function () { };
		delete props.onload;
		props.id = props.name = [props.id, props.name, iframe ? (iframe.id || iframe.name) : 'IFrame_' + String.uniqueID()].pick();
		iframe = new Element(iframe || 'iframe', props);

		var onLoad = function () {
			onload.call(iframe.contentWindow);
		};

		if (window.frames[props.id]) {
			onLoad();
		} else {
			iframe.addListener('load', onLoad);
		}
		return iframe;
	});

	// #endregion

	// #region - Elements -

	var Elements = this.Elements = function (nodes) {
		if (nodes && nodes.length) {
			var uniques = {}, node;
			/**
			# 苦苦的苦瓜 
			# 2011-10-12
			# for循环改为while循环
			# for (var i = 0; node = nodes[i++]; ) {
			**/
			var i = 0;
			while (node = nodes[i++]) {
				var uid = Slick.uidOf(node);
				if (!uniques[uid]) {
					uniques[uid] = true;
					this.push(node);
				}
			}
		}
	};

	Elements.prototype = { length: 0 };
	Elements.parent = Array;

	new Type('Elements', Elements).implement({

		filter: function (filter, bind) {
			if (!filter) { return this; }
			return new Elements(Array.filter(this, (typeOf(filter) == 'string') ? function (item) {
				return item.match(filter);
			} : filter, bind));
		} .protect(),

		push: function () {
			var length = this.length,
					$_docID = document.id; // # 苦苦的苦瓜 2011-10-08
			/**
			# 苦苦的苦瓜 
			# 2011-10-12
			# for循环改为while循环
			# for (var i = 0, l = arguments.length; i < l; i++) {
			**/
			var i = 0, l = arguments.length;
			while (i < l) {
				var item = $_docID(arguments[i++]);
				if (item) { this[length++] = item; }
			}
			return (this.length = length);
		} .protect(),

		unshift: function () {
			var items = [],
					$_docID = document.id; // # 苦苦的苦瓜 2011-10-08
			/**
			# 苦苦的苦瓜 
			# 2011-10-12
			# for循环改为while循环
			# for (var i = 0, l = arguments.length; i < l; i++) {
			**/
			var i = 0, l = arguments.length;
			while (i < l) {
				var item = $_docID(arguments[i++]);
				if (item) { items.push(item); }
			}
			return Array.prototype.unshift.apply(this, items);
		} .protect(),

		concat: function () {
			var newElements = new Elements(this);
			/**
			# 苦苦的苦瓜 
			# 2011-10-12
			# for循环改为while循环
			# for (var i = 0, l = arguments.length; i < l; i++) {
			**/
			var i = 0, l = arguments.length;
			while (i < l) {
				var item = arguments[i++];
				if (Type.isEnumerable(item)) {
					newElements.append(item);
				} else {
					newElements.push(item);
				}
			}
			return newElements;
		} .protect(),

		append: function (collection) {
			/**
			# 苦苦的苦瓜 
			# 2011-10-12
			# for循环改为while循环
			# for (var i = 0, l = collection.length; i < l; i++) {
			**/
			var i = 0, l = collection.length;
			while (i < l) {
				this.push(collection[i++]);
			}
			return this;
		} .protect(),

		empty: function () {
			while (this.length) {
				delete this[--this.length];
			}
			return this;
		} .protect()

	});

	// #endregion

	// #region - Document -

	(function () {

		// FF, IE
		var splice = Array.prototype.splice,
				object = { '0': 0, '1': 1, length: 2 };

		splice.call(object, 1, 1);
		if (object[1] == 1) {
			Elements.implement('splice', function () {
				var length = this.length;
				var result = splice.apply(this, arguments);
				while (length >= this.length) {
					delete this[length--];
				}
				return result;
			} .protect());
		}

		Elements.implement(Array.prototype);

		Array.mirror(Elements);

		/*<ltIE8>*/
		var createElementAcceptsHTML;
		try {
			var x = document.createElement('<input name=x>');
			createElementAcceptsHTML = (x.name == 'x');
		} catch (e) { }

		var escapeQuotes = function (html) {
			return ('' + html).replace(/&/g, '&amp;').replace(/"/g, '&quot;');
		};
		/*</ltIE8>*/

		Document.implement({

			newElement: function (tag, props) {
				if (props && props.checked != null) {
					props.defaultChecked = props.checked;
				}
				/*<ltIE8>*/// Fix for readonly name and type properties in IE < 8
				if (createElementAcceptsHTML && props) {
					tag = '<' + tag;
					if (props.name) {
						tag += ' name="' + escapeQuotes(props.name) + '"';
					}
					if (props.type) {
						tag += ' type="' + escapeQuotes(props.type) + '"';
					}
					tag += '>';
					delete props.name;
					delete props.type;
				}
				/*</ltIE8>*/
				return this.id(this.createElement(tag)).set(props);
			}

		});

	})();

	Document.implement({

		newTextNode: function (text) {
			return this.createTextNode(text);
		},

		getDocument: function () {
			return this;
		},

		getWindow: function () {
			return this.window;
		},

		id: (function () {

			var types = {

				string: function (id, nocash, doc) {
					id = Slick.find(doc, '#' + id.replace(/(\W)/g, '\\$1'));
					return (id) ? types.element(id, nocash) : null;
				},

				element: function (el, nocash) {
					$uid(el);
					if (!nocash && !el.$family && !(/^(?:object|embed)$/i).test(el.tagName)) {
						Object.append(el, Element.Prototype);
					}
					return el;
				},

				object: function (obj, nocash, doc) {
					if (obj.toElement) {
						return types.element(obj.toElement(doc), nocash);
					}
					return null;
				}

			};

			types.textnode = types.whitespace = types.window = types.document = function (zero) {
				return zero;
			};

			return function (el, nocash, doc) {
				if (el && el.$family && el.uid) {
					return el;
				}
				var type = typeOf(el);
				return (types[type]) ? types[type](el, nocash, doc || document) : null;
			};

		})()

	});

	// #endregion

	// #region - Window -

	if (window.$ == null) {
		Window.implement('$', function (el, nc) {
			return document.id(el, nc, this.document);
		});
	}

	Window.implement({

		getDocument: function () {
			return this.document;
		},

		getWindow: function () {
			return this;
		}

	});

	// #endregion

	// #region - Element Methods -

	// #region getElement, getElements

	[Document, Element].invoke('implement', {

		getElements: function (expression) {
			return Slick.search(this, expression, new Elements);
		},

		getElement: function (expression) {
			return document.id(Slick.find(this, expression));
		}

	});

	// #endregion

	// #region contains

	var contains = {
		contains: function (element) {
			return Slick.contains(this, element);
		}
	};

	if (!document.contains) {
		Document.implement(contains);
	}
	if (!document.createElement('div').contains) {
		Element.implement(contains);
	}

	// #endregion

	// #region tree walking

	var injectCombinator = function (expression, combinator) {
		if (!expression) { return combinator; }

		expression = Object.clone(Slick.parse(expression));

		var expressions = expression.expressions;
		/**
		# 苦苦的苦瓜 
		# 2011-10-12
		# for循环改为while循环
		# for (var i = expressions.length; i--; ) {
		**/
		var i = expressions.length;
		while (i--) {
			expressions[i][0].combinator = combinator;
		}

		return expression;
	};

	Object.forEach({
		getNext: '~',
		getPrevious: '!~',
		getParent: '!'
	}, function (combinator, method) {
		Element.implement(method, function (expression) {
			return this.getElement(injectCombinator(expression, combinator));
		});
	});

	Object.forEach({
		getAllNext: '~',
		getAllPrevious: '!~',
		getSiblings: '~~',
		getChildren: '>',
		getParents: '!'
	}, function (combinator, method) {
		Element.implement(method, function (expression) {
			return this.getElements(injectCombinator(expression, combinator));
		});
	});

	// #endregion

	Element.implement({

		getFirst: function (expression) {
			return document.id(Slick.search(this, injectCombinator(expression, '>'))[0]);
		},

		getLast: function (expression) {
			return document.id(Slick.search(this, injectCombinator(expression, '>')).getLast());
		},

		getWindow: function () {
			return this.ownerDocument.window;
		},

		getDocument: function () {
			return this.ownerDocument;
		},

		getElementById: function (id) {
			return document.id(Slick.find(this, '#' + ('' + id).replace(/(\W)/g, '\\$1')));
		},

		match: function (expression) {
			return !expression || Slick.match(this, expression);
		}

	});

	// #region $$

	if (window.$$ == null) {
		Window.implement('$$', function (selector) {
			if (arguments.length == 1) {
				if (typeof selector == 'string') {
					return Slick.search(this.document, selector, new Elements);
				} else if (Type.isEnumerable(selector)) {
					return new Elements(selector);
				}
			}
			return new Elements(arguments);
		});
	}

	// #endregion

	(function () {

		// Inserters

		var inserters = {

			before: function (context, element) {
				var parent = element.parentNode;
				if (parent) {
					parent.insertBefore(context, element);
				}
			},

			after: function (context, element) {
				var parent = element.parentNode;
				if (parent) {
					parent.insertBefore(context, element.nextSibling);
				}
			},

			bottom: function (context, element) {
				element.appendChild(context);
			},

			top: function (context, element) {
				element.insertBefore(context, element.firstChild);
			}

		};

		inserters.inside = inserters.bottom;

		// getProperty / setProperty

		var propertyGetters = {}, propertySetters = {};

		// properties

		var properties = {};
		Array.forEach(['type', 'value', 'defaultValue', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', 'frameBorder', 'readOnly', 'rowSpan', 'tabIndex', 'useMap'], function (property) {
			properties[property.toLowerCase()] = property;
		});

		Object.append(properties, {
			'html': 'innerHTML',
			'text': (function () {
				var temp = document.createElement('div');
				return (temp.textContent == null) ? 'innerText' : 'textContent';
			})()
		});

		Object.forEach(properties, function (real, key) {
			propertySetters[key] = function (node, value) {
				node[real] = value;
			};
			propertyGetters[key] = function (node) {
				return node[real];
			};
		});

		// Booleans

		var bools = [
				'compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked',
				'disabled', 'readOnly', 'multiple', 'selected', 'noresize',
				'defer', 'defaultChecked', 'autofocus', 'controls', 'autoplay',
				'loop'];

		var booleans = {};
		Array.forEach(bools, function (bool) {
			var lower = bool.toLowerCase();
			booleans[lower] = bool;
			propertySetters[lower] = function (node, value) {
				node[bool] = !!value;
			};
			propertyGetters[lower] = function (node) {
				return !!node[bool];
			};
		});

		// Special cases

		Object.append(propertySetters, {

			'class': function (node, value) {
				('className' in node) ? node.className = value : node.setAttribute('class', value);
			},

			'for': function (node, value) {
				('htmlFor' in node) ? node.htmlFor = value : node.setAttribute('for', value);
			},

			'style': function (node, value) {
				(node.style) ? node.style.cssText = value : node.setAttribute('style', value);
			}

		});

		/* getProperty, setProperty */

		Element.implement({

			setProperty: function (name, value) {
				var lower = name.toLowerCase();
				if (value == null) {
					if (!booleans[lower]) {
						this.removeAttribute(name);
						return this;
					}
					value = false;
				}
				var setter = propertySetters[lower];
				if (setter) {
					setter(this, value);
				} else {
					this.setAttribute(name, value);
				}
				return this;
			},

			setProperties: function (attributes) {
				for (var attribute in attributes) {
					this.setProperty(attribute, attributes[attribute]);
				}
				return this;
			},

			getProperty: function (name) {
				var getter = propertyGetters[name.toLowerCase()];
				if (getter) { return getter(this); }
				var result = Slick.getAttribute(this, name);
				return (!result && !Slick.hasAttribute(this, name)) ? null : result;
			},

			getProperties: function () {
				var args = Array.from(arguments);
				return args.map(this.getProperty, this).associate(args);
			},

			removeProperty: function (name) {
				return this.setProperty(name, null);
			},

			removeProperties: function () {
				Array.each(arguments, this.removeProperty, this);
				return this;
			},

			set: function (prop, value) {
				var property = Element.Properties[prop];
				(property && property.set) ? property.set.call(this, value) : this.setProperty(prop, value);
			} .overloadSetter(),

			get: function (prop) {
				var property = Element.Properties[prop];
				return (property && property.get) ? property.get.apply(this) : this.getProperty(prop);
			} .overloadGetter(),

			erase: function (prop) {
				var property = Element.Properties[prop];
				(property && property.erase) ? property.erase.apply(this) : this.removeProperty(prop);
				return this;
			},

			hasClass: function (className) {
				return this.className.clean().contains(className, ' ');
			},

			addClass: function (className) {
				if (!this.hasClass(className)) {
					this.className = (this.className + ' ' + className).clean();
				}
				return this;
			},

			removeClass: function (className) {
				this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1');
				return this;
			},

			toggleClass: function (className, force) {
				if (force == null) {
					force = !this.hasClass(className);
				}
				return (force) ? this.addClass(className) : this.removeClass(className);
			},

			adopt: function () {
				var parent = this,
						fragment,
						elements = Array.flatten(arguments),
						length = elements.length,
						$_doc = document, // # 苦苦的苦瓜 2011-10-12
						$_docID = $_doc.id;
				if (length > 1) {
					parent = fragment = $_doc.createDocumentFragment();
				}

				/**
				# 苦苦的苦瓜 
				# 2011-10-12
				# for循环改为while循环
				# for (var i = 0; i < length; i++) {
				**/
				var i = 0
				while (i < length) {
					var element = $_docID(elements[i++], true);
					if (element) { parent.appendChild(element); }
				}

				if (fragment) { this.appendChild(fragment); }

				return this;
			},

			appendText: function (text, where) {
				return this.grab(this.getDocument().newTextNode(text), where);
			},

			grab: function (el, where) {
				inserters[where || 'bottom'](document.id(el, true), this);
				return this;
			},

			inject: function (el, where) {
				inserters[where || 'bottom'](this, document.id(el, true));
				return this;
			},

			replaces: function (el) {
				el = document.id(el, true);
				el.parentNode.replaceChild(this, el);
				return this;
			},

			wraps: function (el, where) {
				el = document.id(el, true);
				return this.replaces(el).grab(el, where);
			},

			getSelected: function () {
				this.selectedIndex; // Safari 3.2.1
				return new Elements(Array.from(this.options).filter(function (option) {
					return option.selected;
				}));
			},

			toQueryString: function () {
				var queryString = [];
				this.getElements('input, select, textarea').each(function (el) {
					var type = el.type;
					if (!el.name || el.disabled || type == 'submit' || type == 'reset' || type == 'file' || type == 'image') {
						return;
					}

					var value = (el.get('tag') == 'select') ? el.getSelected().map(function (opt) {
						// IE
						return document.id(opt).get('value');
					}) : ((type == 'radio' || type == 'checkbox') && !el.checked) ? null : el.get('value');

					Array.from(value).each(function (val) {
						if (typeof val != 'undefined') {
							queryString.push(encodeURIComponent(el.name) + '=' + encodeURIComponent(val));
						}
					});
				});
				return queryString.join('&');
			}

		});

		var collected = {},
				storage = {};

		var get = function (uid) {
			return (storage[uid] || (storage[uid] = {}));
		};

		var clean = function (item) {
			var uid = item.uid;
			if (item.removeEvents) {
				item.removeEvents();
			}
			if (item.clearAttributes) {
				item.clearAttributes();
			}
			if (uid != null) {
				delete collected[uid];
				delete storage[uid];
			}
			return item;
		};

		var formProps = { input: 'checked', option: 'selected', textarea: 'value' };

		Element.implement({

			destroy: function () {
				var children = clean(this).getElementsByTagName('*');
				Array.each(children, clean);
				Element.dispose(this);
				return null;
			},

			empty: function () {
				Array.from(this.childNodes).each(Element.dispose);
				return this;
			},

			dispose: function () {
				return (this.parentNode) ? this.parentNode.removeChild(this) : this;
			},

			clone: function (contents, keepid) {
				contents = contents !== false;
				var clone = this.cloneNode(contents),
						ce = [clone],
						te = [this], i;

				if (contents) {
					ce.append(Array.from(clone.getElementsByTagName('*')));
					te.append(Array.from(this.getElementsByTagName('*')));
				}

				/**
				# 苦苦的苦瓜 
				# 2011-10-12
				# for循环改为while循环
				# for (i = ce.length; i--; ) {
				**/
				i = ce.length;
				while (i--) {
					var node = ce[i], element = te[i];
					if (!keepid) {
						node.removeAttribute('id');
					}
					/*<ltIE9>*/
					if (node.clearAttributes) {
						node.clearAttributes();
						node.mergeAttributes(element);
						node.removeAttribute('uid');
						if (node.options) {
							var no = node.options,
									eo = element.options;
							/**
							# 苦苦的苦瓜 
							# 2011-10-12
							# for循环改为while循环
							# for (var j = no.length; j--; ) {
							**/
							var j = no.length;
							while (j--) {
								no[j].selected = eo[j].selected;
							}
						}
					}
					/*</ltIE9>*/
					var prop = formProps[element.tagName.toLowerCase()];
					if (prop && element[prop]) {
						node[prop] = element[prop];
					}
				}

				/*<ltIE9>*/
				if (Browser.ie) {
					var co = clone.getElementsByTagName('object'),
							to = this.getElementsByTagName('object');
					/**
					# 苦苦的苦瓜 
					# 2011-10-12
					# for循环改为while循环
					# for (i = co.length; i--; ) {
					**/
					i = co.length;
					while (i--) {
						co[i].outerHTML = to[i].outerHTML;
					}
				}
				/*</ltIE9>*/
				return document.id(clone);
			}

		});

		[Element, Window, Document].invoke('implement', {

			addListener: function (type, fn) {
				if (type == 'unload') {
					var old = fn, self = this;
					fn = function () {
						self.removeListener('unload', fn);
						old();
					};
				} else {
					collected[$uid(this)] = this;
				}
				if (this.addEventListener) {
					this.addEventListener(type, fn, !!arguments[2]);
				} else {
					this.attachEvent('on' + type, fn);
				}
				return this;
			},

			removeListener: function (type, fn) {
				if (this.removeEventListener) {
					this.removeEventListener(type, fn, !!arguments[2]);
				} else {
					this.detachEvent('on' + type, fn);
				}
				return this;
			},

			retrieve: function (property, dflt) {
				var storage = get($uid(this)), prop = storage[property];
				if (dflt != null && prop == null) {
					prop = storage[property] = dflt;
				}
				return prop != null ? prop : null;
			},

			store: function (property, value) {
				var storage = get($uid(this));
				storage[property] = value;
				return this;
			},

			eliminate: function (property) {
				var storage = get($uid(this));
				delete storage[property];
				return this;
			}

		});

		/*<ltIE9>*/
		if (window.attachEvent && !window.addEventListener) window.addListener('unload', function () {
			Object.each(collected, clean);
			if (window.CollectGarbage) { CollectGarbage(); }
		});
		/*</ltIE9>*/

		Element.Properties = {};

		Element.Properties.style = {

			set: function (style) {
				this.style.cssText = style;
			},

			get: function () {
				return this.style.cssText;
			},

			erase: function () {
				this.style.cssText = '';
			}

		};

		Element.Properties.tag = {

			get: function () {
				return this.tagName.toLowerCase();
			}

		};

		/*<!webkit>*/
		Element.Properties.html = (function () {

			var tableTest = Function.attempt(function () {
				var table = document.createElement('table');
				table.innerHTML = '<tr><td></td></tr>';
			});

			var wrapper = document.createElement('div');

			var translations = {
				table: [1, '<table>', '</table>'],
				select: [1, '<select>', '</select>'],
				tbody: [2, '<table><tbody>', '</tbody></table>'],
				tr: [3, '<table><tbody><tr>', '</tr></tbody></table>']
			};
			translations.thead = translations.tfoot = translations.tbody;

			/*<ltIE9>*/
			// technique by jdbarlett - http://jdbartlett.com/innershiv/
			wrapper.innerHTML = '<nav></nav>';
			var HTML5Test = wrapper.childNodes.length == 1;
			if (!HTML5Test) {
				var tags = 'abbr article aside audio canvas datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video'.split(' '),
						fragment = document.createDocumentFragment(), l = tags.length;
				while (l--) {
					fragment.createElement(tags[l]);
				}
				fragment.appendChild(wrapper);
			}
			/*</ltIE9>*/

			var html = {
				set: function (html) {
					if (typeOf(html) == 'array') {
						html = html.join('');
					}

					var wrap = (!tableTest && translations[this.get('tag')]);
					/*<ltIE9>*/
					if (!wrap && !HTML5Test) { wrap = [0, '', '']; }
					/*</ltIE9>*/
					if (wrap) {
						var first = wrapper;
						first.innerHTML = wrap[1] + html + wrap[2];
						for (var i = wrap[0]; i--; ) {
							first = first.firstChild;
						}
						this.empty().adopt(first.childNodes);
					} else {
						this.innerHTML = html;
					}
				}
			};

			html.erase = html.set;

			return html;
		})();
		/*</!webkit>*/

		/*<ltIE9>*/
		var testForm = document.createElement('form');
		testForm.innerHTML = '<select><option>s</option></select>';

		if (testForm.firstChild.value != 's') {
			Element.Properties.value = {

				set: function (value) {
					var tag = this.get('tag');
					if (tag != 'select') {
						return this.setProperty('value', value);
					}
					var options = this.getElements('option');
					/**
					# 苦苦的苦瓜
					# 2011-10-12
					# for循环改为while循环
					# for (var i = 0; i < options.length; i++) {
					**/
					var i = 0, l = options.length;
					while (i < l) {
						var option = options[i++],
								attr = option.getAttributeNode('value'),
								optionValue = (attr && attr.specified) ? option.value : option.get('text');
						if (optionValue == value) {
							return option.selected = true;
						}
					}
				},

				get: function () {
					var option = this, tag = option.get('tag');

					if (tag != 'select' && tag != 'option') {
						return this.getProperty('value');
					}

					if (tag == 'select' && !(option = option.getSelected()[0])) {
						return '';
					}

					var attr = option.getAttributeNode('value');
					return (attr && attr.specified) ? option.value : option.get('text');
				}

			};
		}
		/*</ltIE9>*/

	})();

	// #endregion

	// #endregion

	// #region -- Element.Style --

	/*
	---

	name: Element.Style

	description: Contains methods for interacting with the styles of Elements in a fashionable way.

	license: MIT-style license.

	requires: Element

	provides: Element.Style

	...
	*/

	(function () {

		var html = document.html;

		Element.Properties.styles = {
			set: function (styles) {
				this.setStyles(styles);
			}
		};

		var hasOpacity = (html.style.opacity != null),
				hasFilter = (html.style.filter != null),
				reAlpha = /alpha\(opacity=([\d.]+)\)/i;

		var setVisibility = function (element, opacity) {
			element.store('$opacity', opacity);
			element.style.visibility = opacity > 0 ? 'visible' : 'hidden';
		};

		var setOpacity = (hasOpacity ? function (element, opacity) {
			element.style.opacity = opacity;
		} : (hasFilter ? function (element, opacity) {
			if (!element.currentStyle || !element.currentStyle.hasLayout) {
				element.style.zoom = 1;
			}
			opacity = (opacity * 100).limit(0, 100).round();
			opacity = (opacity == 100) ? '' : 'alpha(opacity=' + opacity + ')';
			var filter = element.style.filter || element.getComputedStyle('filter') || '';
			element.style.filter = reAlpha.test(filter) ? filter.replace(reAlpha, opacity) : filter + opacity;
		} : setVisibility));

		var getOpacity = (hasOpacity ? function (element) {
			var opacity = element.style.opacity || element.getComputedStyle('opacity');
			return (opacity == '') ? 1 : opacity.toFloat();
		} : (hasFilter ? function (element) {
			var filter = (element.style.filter || element.getComputedStyle('filter')),
					opacity;
			if (filter) { opacity = filter.match(reAlpha); }
			return (opacity == null || filter == null) ? 1 : (opacity[1] / 100);
		} : function (element) {
			var opacity = element.retrieve('$opacity');
			if (opacity == null) { opacity = (element.style.visibility == 'hidden' ? 0 : 1); }
			return opacity;
		}));

		var floatName = (html.style.cssFloat == null) ? 'styleFloat' : 'cssFloat';

		Element.implement({

			getComputedStyle: function (property) {
				if (this.currentStyle) {
					return this.currentStyle[property.camelCase()];
				}
				var defaultView = Element.getDocument(this).defaultView,
					computed = defaultView ? defaultView.getComputedStyle(this, null) : null;
				return (computed) ? computed.getPropertyValue((property == floatName) ? 'float' : property.hyphenate()) : null;
			},

			setStyle: function (property, value) {
				if (property == 'opacity') {
					setOpacity(this, parseFloat(value));
					return this;
				}
				property = (property == 'float' ? floatName : property).camelCase();
				if (typeOf(value) != 'string') {
					var map = (Element.Styles[property] || '@').split(' ');
					value = Array.from(value).map(function (val, i) {
						if (!map[i]) { return ''; }
						return (typeOf(val) == 'number') ? map[i].replace('@', Math.round(val)) : val;
					}).join(' ');
				} else if (value == String(Number(value))) {
					value = Math.round(value);
				}
				this.style[property] = value;
				return this;
			},

			getStyle: function (property) {
				if (property == 'opacity') { return getOpacity(this); }
				property = (property == 'float' ? floatName : property).camelCase();
				var result = this.style[property];
				if (!result || property == 'zIndex') {
					result = [];
					for (var style in Element.ShortStyles) {
						if (property != style) { continue; }
						for (var s in Element.ShortStyles[style]) {
							result.push(this.getStyle(s));
						}
						return result.join(' ');
					}
					result = this.getComputedStyle(property);
				}
				if (result) {
					result = String(result);
					var color = result.match(/rgba?\([\d\s,]+\)/);
					if (color) {
						result = result.replace(color[0], color[0].rgbToHex());
					}
				}
				if (Browser.opera || (Browser.ie && isNaN(parseFloat(result)))) {
					if ((/^(height|width)$/).test(property)) {
						var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'], size = 0;
						values.each(function (value) {
							size += this.getStyle('border-' + value + '-width').toInt() + this.getStyle('padding-' + value).toInt();
						}, this);
						return this['offset' + property.capitalize()] - size + 'px';
					}
					if (Browser.opera && String(result).indexOf('px') != -1) {
						return result;
					}
					if ((/^border(.+)Width|margin|padding/).test(property)) {
						return '0px';
					}
				}
				return result;
			},

			setStyles: function (styles) {
				for (var style in styles) {
					this.setStyle(style, styles[style]);
				}
				return this;
			},

			getStyles: function () {
				var result = {};
				Array.flatten(arguments).each(function (key) {
					result[key] = this.getStyle(key);
				}, this);
				return result;
			}

		});

		Element.Styles = {
			left: '@px', top: '@px', bottom: '@px', right: '@px',
			width: '@px', height: '@px', maxWidth: '@px', maxHeight: '@px', minWidth: '@px', minHeight: '@px',
			backgroundColor: 'rgb(@, @, @)', backgroundPosition: '@px @px', color: 'rgb(@, @, @)',
			fontSize: '@px', letterSpacing: '@px', lineHeight: '@px', clip: 'rect(@px @px @px @px)',
			margin: '@px @px @px @px', padding: '@px @px @px @px', border: '@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)',
			borderWidth: '@px @px @px @px', borderStyle: '@ @ @ @', borderColor: 'rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)',
			zIndex: '@', 'zoom': '@', fontWeight: '@', textIndent: '@px', opacity: '@'
		};

		Element.ShortStyles = { margin: {}, padding: {}, border: {}, borderWidth: {}, borderStyle: {}, borderColor: {} };

		['Top', 'Right', 'Bottom', 'Left'].each(function (direction) {
			var Short = Element.ShortStyles;
			var All = Element.Styles;
			['margin', 'padding'].each(function (style) {
				var sd = style + direction;
				Short[style][sd] = All[sd] = '@px';
			});
			var bd = 'border' + direction;
			Short.border[bd] = All[bd] = '@px @ rgb(@, @, @)';
			var bdw = bd + 'Width', bds = bd + 'Style', bdc = bd + 'Color';
			Short[bd] = {};
			Short.borderWidth[bdw] = Short[bd][bdw] = All[bdw] = '@px';
			Short.borderStyle[bds] = Short[bd][bds] = All[bds] = '@';
			Short.borderColor[bdc] = Short[bd][bdc] = All[bdc] = 'rgb(@, @, @)';
		});

	})();

	// #endregion

	// #region -- Element.Event --

	/*
	---

	name: Element.Event

	description: Contains Element methods for dealing with events. This file also includes mouseenter and mouseleave custom Element Events.

	license: MIT-style license.

	requires: [Element, Event]

	provides: Element.Event

	...
	*/

	(function () {

		Element.Properties.events = {
			set: function (events) {
				this.addEvents(events);
			}
		};

		[Element, Window, Document].invoke('implement', {

			addEvent: function (type, fn) {
				var events = this.retrieve('events', {});
				if (!events[type]) {
					events[type] = { keys: [], values: [] };
				}
				if (events[type].keys.contains(fn)) {
					return this;
				}
				events[type].keys.push(fn);
				var realType = type,
						custom = Element.Events[type],
						condition = fn,
						self = this;
				if (custom) {
					if (custom.onAdd) {
						custom.onAdd.call(this, fn, type);
					}
					if (custom.condition) {
						condition = function (event) {
							if (custom.condition.call(this, event, type)) {
								return fn.call(this, event);
							}
							return true;
						};
					}
					if (custom.base) {
						realType = Function.from(custom.base).call(this, type);
					}
				}
				var defn = function () {
					return fn.call(self);
				};
				var nativeEvent = Element.NativeEvents[realType];
				if (nativeEvent) {
					if (nativeEvent == 2) {
						defn = function (event) {
							event = new DOMEvent(event, self.getWindow());
							if (condition.call(self, event) === false) {
								event.stop();
							}
						};
					}
					this.addListener(realType, defn, arguments[2]);
				}
				events[type].values.push(defn);
				return this;
			},

			removeEvent: function (type, fn) {
				var events = this.retrieve('events');
				if (!events || !events[type]) {
					return this;
				}
				var list = events[type];
				var index = list.keys.indexOf(fn);
				if (index == -1) {
					return this;
				}
				var value = list.values[index];
				delete list.keys[index];
				delete list.values[index];
				var custom = Element.Events[type];
				if (custom) {
					if (custom.onRemove) {
						custom.onRemove.call(this, fn, type);
					}
					if (custom.base) {
						type = Function.from(custom.base).call(this, type);
					}
				}
				return (Element.NativeEvents[type]) ? this.removeListener(type, value, arguments[2]) : this;
			},

			addEvents: function (events) {
				for (var event in events) {
					this.addEvent(event, events[event]);
				}
				return this;
			},

			removeEvents: function (events) {
				var type;
				if (typeOf(events) == 'object') {
					for (type in events) {
						this.removeEvent(type, events[type]);
					}
					return this;
				}
				var attached = this.retrieve('events');
				if (!attached) { return this; }
				if (!events) {
					for (type in attached) {
						this.removeEvents(type);
					}
					this.eliminate('events');
				} else if (attached[events]) {
					attached[events].keys.each(function (fn) {
						this.removeEvent(events, fn);
					}, this);
					delete attached[events];
				}
				return this;
			},

			fireEvent: function (type, args, delay) {
				var events = this.retrieve('events');
				if (!events || !events[type]) { return this; }
				args = Array.from(args);

				events[type].keys.each(function (fn) {
					if (delay) {
						fn.delay(delay, this, args);
					} else {
						fn.apply(this, args);
					}
				}, this);
				return this;
			},

			cloneEvents: function (from, type) {
				from = document.id(from);
				var events = from.retrieve('events');
				if (!events) { return this; }
				if (!type) {
					for (var eventType in events) {
						this.cloneEvents(from, eventType);
					}
				} else if (events[type]) {
					events[type].keys.each(function (fn) {
						this.addEvent(type, fn);
					}, this);
				}
				return this;
			}

		});

		Element.NativeEvents = {
			click: 2, dblclick: 2, mouseup: 2, mousedown: 2, contextmenu: 2, //mouse buttons
			mousewheel: 2, DOMMouseScroll: 2, //mouse wheel
			mouseover: 2, mouseout: 2, mousemove: 2, selectstart: 2, selectend: 2, //mouse movement
			keydown: 2, keypress: 2, keyup: 2, //keyboard
			orientationchange: 2, // mobile
			touchstart: 2, touchmove: 2, touchend: 2, touchcancel: 2, // touch
			gesturestart: 2, gesturechange: 2, gestureend: 2, // gesture
			focus: 2, blur: 2, change: 2, reset: 2, select: 2, submit: 2, paste: 2, input: 2, //form elements
			load: 2, unload: 1, beforeunload: 2, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window
			error: 1, abort: 1, scroll: 1 //misc
		};

		var check = function (event) {
			var related = event.relatedTarget;
			if (related == null) { return true; }
			if (!related) { return false; }
			return (related != this && related.prefix != 'xul' && typeOf(this) != 'document' && !this.contains(related));
		};

		Element.Events = {

			mouseenter: {
				base: 'mouseover',
				condition: check
			},

			mouseleave: {
				base: 'mouseout',
				condition: check
			},

			mousewheel: {
				base: (Browser.firefox) ? 'DOMMouseScroll' : 'mousewheel'
			}

		};

		/*<ltIE9>*/
		if (!window.addEventListener) {
			Element.NativeEvents.propertychange = 2;
			Element.Events.change = {
				base: function () {
					var type = this.type;
					return (this.get('tag') == 'input' && (type == 'radio' || type == 'checkbox')) ? 'propertychange' : 'change'
				},
				condition: function (event) {
					return !!(this.type != 'radio' || this.checked);
				}
			}
		}
		/*</ltIE9>*/

	})();

	// #endregion

	// #region -- Element.Delegation --

	/*
	---

	name: Element.Delegation

	description: Extends the Element native object to include the delegate method for more efficient event management.

	license: MIT-style license.

	requires: [Element.Event]

	provides: [Element.Delegation]

	...
	*/

	(function () {

		var eventListenerSupport = !!window.addEventListener;

		Element.NativeEvents.focusin = Element.NativeEvents.focusout = 2;

		var bubbleUp = function (self, match, fn, event, target) {
			while (target && target != self) {
				if (match(target, event)) {
					return fn.call(target, event, target);
				}
				target = document.id(target.parentNode);
			}
		};

		var map = {
			mouseenter: {
				base: 'mouseover'
			},
			mouseleave: {
				base: 'mouseout'
			},
			focus: {
				base: 'focus' + (eventListenerSupport ? '' : 'in'),
				capture: true
			},
			blur: {
				base: eventListenerSupport ? 'blur' : 'focusout',
				capture: true
			}
		};

		/*<ltIE9>*/
		var _key = '$delegation:';
		var formObserver = function (type) {

			return {

				base: 'focusin',

				remove: function (self, uid) {
					var list = self.retrieve(_key + type + 'listeners', {})[uid];
					if (list && list.forms) {
						/**
						# 苦苦的苦瓜 
						# 2011-10-12
						# for循环改为while循环
						# for (var i = $_forms.length; i--; ) {
						**/
						var $_forms = list.forms,
								i = $_forms.length;
						while (i--) {
							$_forms[i].removeEvent(type, list.fns[i]);
						}
					}
				},

				listen: function (self, match, fn, event, target, uid) {
					var form = (target.get('tag') == 'form') ? target : event.target.getParent('form');

					if (!form) { return; }

					var listeners = self.retrieve(_key + type + 'listeners', {}),
							listener = listeners[uid] || { forms: [], fns: [] },
							forms = listener.forms, fns = listener.fns;

					if (forms.indexOf(form) != -1) { return; }
					forms.push(form);

					var _fn = function (event) {
						bubbleUp(self, match, fn, event, target);
					};
					form.addEvent(type, _fn);
					fns.push(_fn);

					listeners[uid] = listener;
					self.store(_key + type + 'listeners', listeners);
				}
			};
		};

		var inputObserver = function (type) {
			return {
				base: 'focusin',
				listen: function (self, match, fn, event, target) {
					var events = {
						blur: function () {
							this.removeEvents(events);
						}
					};
					events[type] = function (event) {
						bubbleUp(self, match, fn, event, target);
					};
					event.target.addEvents(events);
				}
			};
		};

		if (!eventListenerSupport) {
			Object.append(map, {
				submit: formObserver('submit'),
				reset: formObserver('reset'),
				change: inputObserver('change'),
				select: inputObserver('select')
			});
		}
		/*</ltIE9>*/

		var proto = Element.prototype,
				addEvent = proto.addEvent,
				removeEvent = proto.removeEvent;

		var relay = function (old, method) {
			return function (type, fn, useCapture) {
				if (type.indexOf(':relay') == -1) {
					return old.call(this, type, fn, useCapture);
				}
				var parsed = Slick.parse(type).expressions[0][0];
				if (parsed.pseudos[0].key != 'relay') {
					return old.call(this, type, fn, useCapture);
				}
				var newType = parsed.tag;
				parsed.pseudos.slice(1).each(function (pseudo) {
					newType += ':' + pseudo.key + (pseudo.value ? '(' + pseudo.value + ')' : '');
				});
				old.call(this, type, fn);
				return method.call(this, newType, parsed.pseudos[0].value, fn);
			};
		};

		var delegation = {

			addEvent: function (type, match, fn) {
				var storage = this.retrieve('$delegates', {}), stored = storage[type];
				if (stored) {
					for (var _uid in stored) {
						var $_item = stored[_uid]; // # 苦苦的苦瓜 2011-10-08
						if ($_item.fn == fn && $_item.match == match) {
							return this;
						}
					}
				}

				var _type = type,
						_match = match,
						_fn = fn,
						_map = map[type] || {};
				type = _map.base || _type;

				match = function (target) {
					return Slick.match(target, _match);
				};

				var elementEvent = Element.Events[_type];
				if (elementEvent && elementEvent.condition) {
					var __match = match,
							condition = elementEvent.condition;
					match = function (target, event) {
						return __match(target, event) && condition.call(target, event, type);
					};
				}

				var self = this,
						uid = String.uniqueID();
				var delegator = _map.listen ? function (event, target) {
					if (!target && event && event.target) {
						target = event.target;
					}
					if (target) {
						_map.listen(self, match, fn, event, target, uid);
					}
				} : function (event, target) {
					if (!target && event && event.target) {
						target = event.target;
					}
					if (target) {
						bubbleUp(self, match, fn, event, target);
					}
				};

				if (!stored) { stored = {}; }
				stored[uid] = {
					match: _match,
					fn: _fn,
					delegator: delegator
				};
				storage[_type] = stored;
				return addEvent.call(this, type, delegator, _map.capture);
			},

			removeEvent: function (type, match, fn, _uid) {
				var storage = this.retrieve('$delegates', {}),
						stored = storage[type];
				if (!stored) { return this; }

				if (_uid) {
					var _type = type,
							delegator = stored[_uid].delegator,
							_map = map[type] || {};
					type = _map.base || _type;
					if (_map.remove) { _map.remove(this, _uid); }
					delete stored[_uid];
					storage[_type] = stored;
					return removeEvent.call(this, type, delegator);
				}

				var __uid, s;
				if (fn) for (__uid in stored) {
					s = stored[__uid];
					if (s.match == match && s.fn == fn) {
						return delegation.removeEvent.call(this, type, match, fn, __uid);
					}
				} else for (__uid in stored) {
					s = stored[__uid];
					if (s.match == match) {
						delegation.removeEvent.call(this, type, match, s.fn, __uid);
					}
				}
				return this;
			}

		};

		[Element, Window, Document].invoke('implement', {
			addEvent: relay(addEvent, delegation.addEvent),
			removeEvent: relay(removeEvent, delegation.removeEvent)
		});

	})();

	// #endregion

	// #region -- Element.Dimensions --

	/*
	---

	name: Element.Dimensions

	description: Contains methods to work with size, scroll, or positioning of Elements and the window object.

	license: MIT-style license.

	credits:
	- Element positioning based on the [qooxdoo](http://qooxdoo.org/) code and smart browser fixes, [LGPL License](http://www.gnu.org/licenses/lgpl.html).
	- Viewport dimensions based on [YUI](http://developer.yahoo.com/yui/) code, [BSD License](http://developer.yahoo.com/yui/license.html).

	requires: [Element, Element.Style]

	provides: [Element.Dimensions]

	...
	*/

	(function () {

		var element = document.createElement('div'),
				child = document.createElement('div');
		element.style.height = '0';
		element.appendChild(child);
		var brokenOffsetParent = (child.offsetParent === element);
		element = child = null;

		var isOffset = function (el) {
			return styleString(el, 'position') != 'static' || isBody(el);
		};

		var isOffsetStatic = function (el) {
			return isOffset(el) || (/^(?:table|td|th)$/i).test(el.tagName);
		};

		Element.implement({

			scrollTo: function (x, y) {
				if (isBody(this)) {
					this.getWindow().scrollTo(x, y);
				} else {
					this.scrollLeft = x;
					this.scrollTop = y;
				}
				return this;
			},

			getSize: function () {
				if (isBody(this)) {
					return this.getWindow().getSize();
				}
				return { x: this.offsetWidth, y: this.offsetHeight };
			},

			getScrollSize: function () {
				if (isBody(this)) {
					return this.getWindow().getScrollSize();
				}
				return { x: this.scrollWidth, y: this.scrollHeight };
			},

			getScroll: function () {
				if (isBody(this)) {
					return this.getWindow().getScroll();
				}
				return { x: this.scrollLeft, y: this.scrollTop };
			},

			getScrolls: function () {
				var element = this.parentNode,
						position = { x: 0, y: 0 };
				while (element && !isBody(element)) {
					position.x += element.scrollLeft;
					position.y += element.scrollTop;
					element = element.parentNode;
				}
				return position;
			},

			getOffsetParent: brokenOffsetParent ? function () {
				var element = this;
				if (isBody(element) || styleString(element, 'position') == 'fixed') {
					return null;
				}

				var isOffsetCheck = (styleString(element, 'position') == 'static') ? isOffsetStatic : isOffset;
				while ((element = element.parentNode)) {
					if (isOffsetCheck(element)) {
						return element;
					}
				}
				return null;
			} : function () {
				var element = this;
				if (isBody(element) || styleString(element, 'position') == 'fixed') {
					return null;
				}

				try {
					return element.offsetParent;
				} catch (e) { }
				return null;
			},

			getOffsets: function () {
				var $_bw = Browser, // # 苦苦的苦瓜 2011-10-08
						$_firefox = $_bw.firefox;
				if (this.getBoundingClientRect && !$_bw.Platform.ios) {
					var bound = this.getBoundingClientRect(),
							html = document.id(this.getDocument().documentElement),
							htmlScroll = html.getScroll(),
							elemScrolls = this.getScrolls(),
							isFixed = (styleString(this, 'position') == 'fixed');

					return {
						x: bound.left.toInt() + elemScrolls.x + ((isFixed) ? 0 : htmlScroll.x) - html.clientLeft,
						y: bound.top.toInt() + elemScrolls.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop
					};
				}

				var element = this,
						position = { x: 0, y: 0 };
				if (isBody(this)) { return position; }

				while (element && !isBody(element)) {
					position.x += element.offsetLeft;
					position.y += element.offsetTop;

					if ($_firefox) {
						if (!borderBox(element)) {
							position.x += leftBorder(element);
							position.y += topBorder(element);
						}
						var parent = element.parentNode;
						if (parent && styleString(parent, 'overflow') != 'visible') {
							position.x += leftBorder(parent);
							position.y += topBorder(parent);
						}
					} else if (element != this && bw.safari) {
						position.x += leftBorder(element);
						position.y += topBorder(element);
					}

					element = element.offsetParent;
				}
				if ($_firefox && !borderBox(this)) {
					position.x -= leftBorder(this);
					position.y -= topBorder(this);
				}
				return position;
			},

			getPosition: function (relative) {
				var offset = this.getOffsets(),
						scroll = this.getScrolls();
				var position = {
					x: offset.x - scroll.x,
					y: offset.y - scroll.y
				};

				if (relative && (relative = document.id(relative))) {
					var relativePosition = relative.getPosition();
					return { x: position.x - relativePosition.x - leftBorder(relative), y: position.y - relativePosition.y - topBorder(relative) };
				}
				return position;
			},

			getCoordinates: function (element) {
				if (isBody(this)) {
					return this.getWindow().getCoordinates();
				}
				var position = this.getPosition(element),
						size = this.getSize();
				var obj = {
					left: position.x,
					top: position.y,
					width: size.x,
					height: size.y
				};
				obj.right = obj.left + obj.width;
				obj.bottom = obj.top + obj.height;
				return obj;
			},

			computePosition: function (obj) {
				return {
					left: obj.x - styleNumber(this, 'margin-left'),
					top: obj.y - styleNumber(this, 'margin-top')
				};
			},

			setPosition: function (obj) {
				return this.setStyles(this.computePosition(obj));
			}

		});


		[Document, Window].invoke('implement', {

			getSize: function () {
				var doc = getCompatElement(this);
				return { x: doc.clientWidth, y: doc.clientHeight };
			},

			getScroll: function () {
				var win = this.getWindow(),
						doc = getCompatElement(this);
				return { x: win.pageXOffset || doc.scrollLeft, y: win.pageYOffset || doc.scrollTop };
			},

			getScrollSize: function () {
				var doc = getCompatElement(this),
						min = this.getSize(),
						body = this.getDocument().body,
						$_max = Math.max; // # 苦苦的苦瓜 2011-10-08

				return { x: $_max(doc.scrollWidth, body.scrollWidth, min.x), y: $_max(doc.scrollHeight, body.scrollHeight, min.y) };
			},

			getPosition: function () {
				return { x: 0, y: 0 };
			},

			getCoordinates: function () {
				var size = this.getSize();
				return { top: 0, left: 0, bottom: size.y, right: size.x, height: size.y, width: size.x };
			}

		});

		// private methods

		var styleString = Element.getComputedStyle;

		function styleNumber(element, style) {
			return styleString(element, style).toInt() || 0;
		}

		function borderBox(element) {
			return styleString(element, '-moz-box-sizing') == 'border-box';
		}

		function topBorder(element) {
			return styleNumber(element, 'border-top-width');
		}

		function leftBorder(element) {
			return styleNumber(element, 'border-left-width');
		}

		function isBody(element) {
			return (/^(?:body|html)$/i).test(element.tagName);
		}

		function getCompatElement(element) {
			var doc = element.getDocument();
			return (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
		}

	})();

	//aliases
	Element.alias({ position: 'setPosition' }); //compatability

	[Window, Document, Element].invoke('implement', {

		getHeight: function () {
			return this.getSize().y;
		},

		getWidth: function () {
			return this.getSize().x;
		},

		getScrollTop: function () {
			return this.getScroll().y;
		},

		getScrollLeft: function () {
			return this.getScroll().x;
		},

		getScrollHeight: function () {
			return this.getScrollSize().y;
		},

		getScrollWidth: function () {
			return this.getScrollSize().x;
		},

		getTop: function () {
			return this.getPosition().y;
		},

		getLeft: function () {
			return this.getPosition().x;
		}

	});

	// #endregion

	// #region -- DOMReady --

	/*
	---

	name: DOMReady

	description: Contains the custom event domready.

	license: MIT-style license.

	requires: [Browser, Element, Element.Event]

	provides: [DOMReady, DomReady]

	...
	*/

	(function (window, document) {

		var ready,
				loaded,
				checks = [],
				shouldPoll,
				timer,
				testElement = document.createElement('div');

		var domready = function () {
			clearTimeout(timer);
			if (ready) { return; }
			Browser.loaded = ready = true;
			document.removeListener('DOMContentLoaded', domready).removeListener('readystatechange', check);

			document.fireEvent('domready');
			window.fireEvent('domready');
		};

		var check = function () {
			/**
			# 苦苦的苦瓜 
			# 2011-10-12
			# for循环改为while循环
			# for (var i = checks.length; i--; ) {
			**/
			var i = checks.length
			while (i--) {
				if (checks[i]()) {
					domready();
					return true;
				}
			}
			return false;
		};

		var poll = function () {
			clearTimeout(timer);
			if (!check()) { timer = setTimeout(poll, 10); }
		};

		document.addListener('DOMContentLoaded', domready);

		/*<ltIE8>*/
		// doScroll technique by Diego Perini http://javascript.nwbox.com/IEContentLoaded/
		// testElement.doScroll() throws when the DOM is not ready, only in the top window
		var doScrollWorks = function () {
			try {
				testElement.doScroll();
				return true;
			} catch (e) { }
			return false;
		};
		// If doScroll works already, it can't be used to determine domready
		//   e.g. in an iframe
		if (testElement.doScroll && !doScrollWorks()) {
			checks.push(doScrollWorks);
			shouldPoll = true;
		}
		/*</ltIE8>*/

		if (document.readyState) {
			checks.push(function () {
				var state = document.readyState;
				return (state == 'loaded' || state == 'complete');
			});
		}

		if ('onreadystatechange' in document) {
			document.addListener('readystatechange', check);
		} else {
			shouldPoll = true;
		}

		if (shouldPoll) { poll(); }

		Element.Events.domready = {
			onAdd: function (fn) {
				if (ready) { fn.call(this); }
			}
		};

		// Make sure that domready fires before load
		Element.Events.load = {
			base: 'load',
			onAdd: function (fn) {
				if (loaded && this == window) { fn.call(this); }
			},
			condition: function () {
				if (this == window) {
					domready();
					delete Element.Events.load;
				}
				return true;
			}
		};

		// This is based on the custom load event
		window.addEvent('load', function () {
			loaded = true;
		});

	})(window, document);

	// #endregion

	// #region -- Swiff --

	/*
	---

	name: Swiff

	description: Wrapper for embedding SWF movies. Supports External Interface Communication.

	license: MIT-style license.

	credits:
	- Flash detection & Internet Explorer + Flash Player 9 fix inspired by SWFObject.

	requires: [Options, Object, Element]

	provides: Swiff

	...
	*/

	(function () {

		var Swiff = this.Swiff = new Class({

			Implements: Options,

			options: {
				id: null,
				height: 1,
				width: 1,
				container: null,
				properties: {},
				params: {
					quality: 'high',
					allowScriptAccess: 'always',
					wMode: 'window',
					swLiveConnect: true
				},
				callBacks: {},
				vars: {}
			},

			toElement: function () {
				return this.object;
			},

			initialize: function (path, options) {
				this.instance = 'Swiff_' + String.uniqueID();

				this.setOptions(options);
				options = this.options;
				var id = this.id = options.id || this.instance;
				var container = document.id(options.container);

				Swiff.CallBacks[this.instance] = {};

				var params = options.params, vars = options.vars, callBacks = options.callBacks;
				var properties = Object.append({ height: options.height, width: options.width }, options.properties);

				var self = this;

				for (var callBack in callBacks) {
					Swiff.CallBacks[this.instance][callBack] = (function (option) {
						return function () {
							return option.apply(self.object, arguments);
						};
					})(callBacks[callBack]);
					vars[callBack] = 'Swiff.CallBacks.' + this.instance + '.' + callBack;
				}

				params.flashVars = Object.toQueryString(vars);
				if (Browser.ie) {
					properties.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
					params.movie = path;
				} else {
					properties.type = 'application/x-shockwave-flash';
				}
				properties.data = path;

				var build = '<object id="' + id + '"';
				for (var property in properties) {
					build += ' ' + property + '="' + properties[property] + '"';
				}
				build += '>';
				for (var param in params) {
					if (params[param]) {
						build += '<param name="' + param + '" value="' + params[param] + '" />';
					}
				}
				build += '</object>';
				this.object = ((container) ? container.empty() : new Element('div')).set('html', build).firstChild;
			},

			replaces: function (element) {
				element = document.id(element, true);
				element.parentNode.replaceChild(this.toElement(), element);
				return this;
			},

			inject: function (element) {
				document.id(element, true).appendChild(this.toElement());
				return this;
			},

			remote: function () {
				return Swiff.remote.apply(Swiff, [this.toElement()].append(arguments));
			}

		});

		Swiff.CallBacks = {};

		Swiff.remote = function (obj, fn) {
			var rs = obj.CallFunction('<invoke name="' + fn + '" returntype="javascript">' + __flash__argumentsToXML(arguments, 2) + '</invoke>');
			return eval(rs);
		};

	})();

	// #endregion

	// #region -- Class.Occlude --

	/**
	* name: Class.Occlude
	* 
	* description: Prevents a class from being applied to a DOM element twice.
	* 
	* authors:
	*		- Aaron Newton
	* 
	* requires:
	*		- Core/Class
	*		- Core/Element
	*		- /MooTools.More
	* 
	* provides: [Class.Occlude]
	**/

	Class.Occlude = new Class({

		occlude: function (property, element) {
			element = document.id(element || this.element);
			var instance = element.retrieve(property || this.property);
			if (instance && !this.occluded) {
				return (this.occluded = instance);
			}

			this.occluded = false;
			element.store(property || this.property, this);
			return this.occluded;
		}

	});

	// #endregion

	// #region -- Element.Event.Pseudos --

	/**
	* name: Element.Event.Pseudos
	* 
	* description: Adds the functionality to add pseudo events for Elements
	* 
	* authors:
	* - Arian Stolwijk
	* 
	* requires: [Core/Element.Event, Core/Element.Delegation, Events.Pseudos]
	* 
	* provides: [Element.Event.Pseudos, Element.Delegation]
	**/

	(function () {

		var pseudos = { relay: false },
				copyFromEvents = ['once', 'throttle', 'pause'],
				count = copyFromEvents.length;

		while (count--) {
			pseudos[copyFromEvents[count]] = Events.lookupPseudo(copyFromEvents[count]);
		}

		DOMEvent.definePseudo = function (key, listener) {
			pseudos[key] = listener;
			return this;
		};

		var proto = Element.prototype;
		[Element, Window, Document].invoke('implement', Events.Pseudos(pseudos, proto.addEvent, proto.removeEvent));

	})();

	// #endregion Element.Event.Pseudos

	// #region -- Element.Event.Pseudos.Keys --

	/**
	* name: Element.Event.Pseudos.Keys
	* 
	* description: Adds functionality fire events if certain keycombinations are pressed
	* 
	* authors:
	*		- Arian Stolwijk
	* 
	* requires: [Element.Event.Pseudos]
	* 
	* provides: [Element.Event.Pseudos.Keys]
	**/

	(function () {

		var keysStoreKey = '$moo:keys-pressed',
				keysKeyupStoreKey = '$moo:keys-keyup';

		DOMEvent.definePseudo('keys', function (split, fn, args) {

			var event = args[0],
					keys = [],
					pressed = this.retrieve(keysStoreKey, []);

			keys.append(split.value.replace('++', function () {
				keys.push('+'); // shift++ and shift+++a
				return '';
			}).split('+'));

			pressed.include(event.key);

			if (keys.every(function (key) {
				return pressed.contains(key);
			})) {
				fn.apply(this, args);
			}

			this.store(keysStoreKey, pressed);

			if (!this.retrieve(keysKeyupStoreKey)) {
				var keyup = function (event) {
					(function () {
						pressed = this.retrieve(keysStoreKey, []).erase(event.key);
						this.store(keysStoreKey, pressed);
					}).delay(0, this); // Fix for IE
				};
				this.store(keysKeyupStoreKey, keyup).addEvent('keyup', keyup);
			}

		});

		DOMEvent.defineKeys({
			'16': 'shift',
			'17': 'control',
			'18': 'alt',
			'20': 'capslock',
			'33': 'pageup',
			'34': 'pagedown',
			'35': 'end',
			'36': 'home',
			'144': 'numlock',
			'145': 'scrolllock',
			'186': ';',
			'187': '=',
			'188': ',',
			'190': '.',
			'191': '/',
			'192': '`',
			'219': '[',
			'220': '\\',
			'221': ']',
			'222': "'",
			'107': '+'
		}).defineKey(Browser.firefox ? 109 : 189, '-');

	})();

	// #endregion Element.Event.Pseudos.Keys

	// #region -- Element.Measure --

	/**
	* name: Element.Measure
	* 
	* description: Extends the Element native object to include methods useful in measuring dimensions.
	* 
	* credits: "Element.measure / .expose methods by Daniel Steigerwald License: MIT-style license. Copyright: Copyright (c) 2008 Daniel Steigerwald, daniel.steigerwald.cz"
	* 
	* authors:
	*		- Aaron Newton
	* 
	* requires:
	*		- Core/Element.Style
	*		- Core/Element.Dimensions
	*		- /MooTools.More
	* 
	* provides: [Element.Measure]
	**/

	(function () {

		var getStylesList = function (styles, planes) {
			var list = [];
			Object.each(planes, function (directions) {
				Object.each(directions, function (edge) {
					styles.each(function (style) {
						list.push(style + '-' + edge + (style == 'border' ? '-width' : ''));
					});
				});
			});
			return list;
		};

		var calculateEdgeSize = function (edge, styles) {
			var total = 0;
			Object.each(styles, function (value, style) {
				if (style.test(edge)) {
					total = total + value.toInt();
				}
			});
			return total;
		};

		var isVisible = function (el) {
			return !!(!el || el.offsetHeight || el.offsetWidth);
		};

		Element.implement({

			measure: function (fn) {
				if (isVisible(this)) { return fn.call(this); }
				var parent = this.getParent(),
						toMeasure = [];
				while (!isVisible(parent) && parent != document.body) {
					toMeasure.push(parent.expose());
					parent = parent.getParent();
				}
				var restore = this.expose(),
						result = fn.call(this);
				restore();
				toMeasure.each(function (restore) {
					restore();
				});
				return result;
			},

			expose: function () {
				if (this.getStyle('display') != 'none') {
					return function () { };
				}
				var before = this.style.cssText;
				this.setStyles({
					display: 'block',
					position: 'absolute',
					visibility: 'hidden'
				});
				return function () {
					this.style.cssText = before;
				} .bind(this);
			},

			getDimensions: function (options) {
				options = Object.merge({ computeSize: false }, options);
				var dim = {
					x: 0,
					y: 0
				};

				var getSize = function (el, options) {
					return (options.computeSize) ? el.getComputedSize(options) : el.getSize();
				};

				var parent = this.getParent('body');

				if (parent && this.getStyle('display') == 'none') {
					dim = this.measure(function () {
						return getSize(this, options);
					});
				} else if (parent) {
					try { //safari sometimes crashes here, so catch it
						dim = getSize(this, options);
					} catch (e) { }
				}

				return Object.append(dim, (dim.x || dim.x === 0) ? {
					width: dim.x,
					height: dim.y
				} : {
					x: dim.width,
					y: dim.height
				});
			},

			getComputedSize: function (options) {
				options = Object.merge({
					styles: ['padding', 'border'],
					planes: {
						height: ['top', 'bottom'],
						width: ['left', 'right']
					},
					mode: 'both'
				}, options);

				var styles = {},
						size = { width: 0, height: 0 },
						dimensions;

				if (options.mode == 'vertical') {
					delete size.width;
					delete options.planes.width;
				} else if (options.mode == 'horizontal') {
					delete size.height;
					delete options.planes.height;
				}

				getStylesList(options.styles, options.planes).each(function (style) {
					styles[style] = this.getStyle(style).toInt();
				}, this);

				Object.each(options.planes, function (edges, plane) {

					var capitalized = plane.capitalize(),
							style = this.getStyle(plane);

					if (style == 'auto' && !dimensions) {
						dimensions = this.getDimensions();
					}

					style = styles[plane] = (style == 'auto') ? dimensions[plane] : style.toInt();
					size['total' + capitalized] = style;

					edges.each(function (edge) {
						var edgesize = calculateEdgeSize(edge, styles);
						size['computed' + edge.capitalize()] = edgesize;
						size['total' + capitalized] += edgesize;
					});

				}, this);

				return Object.append(size, styles);
			}

		});

	})();

	// #endregion

	// #region -- Element.Pin --

	/**
	* name: Element.Pin
	* 
	* description: Extends the Element native object to include the pin method useful for fixed positioning for elements.
	* 
	* authors:
	*		- Aaron Newton
	* 
	* requires:
	*		- Core/Element.Event
	*		- Core/Element.Dimensions
	*		- Core/Element.Style
	*		- /MooTools.More
	* 
	* provides: [Element.Pin]
	**/

	(function () {

		var supportsPositionFixed = false,
				supportTested = false;

		var testPositionFixed = function () {
			var test = new Element('div').setStyles({
				position: 'fixed',
				top: 0,
				right: 0
			}).inject(document.body);
			supportsPositionFixed = (test.offsetTop === 0);
			test.dispose();
			supportTested = true;
		};

		Element.implement({

			pin: function (enable, forceScroll) {
				if (!supportTested) { testPositionFixed(); }
				if (this.getStyle('display') == 'none') { return this; }

				var pinnedPosition,
						scroll = window.getScroll(),
						parent,
						scrollFixer;

				if (enable !== false) {
					pinnedPosition = this.getPosition(supportsPositionFixed ? document.body : this.getOffsetParent());
					if (!this.retrieve('pin:_pinned')) {
						var currentPosition = {
							top: pinnedPosition.y - scroll.y,
							left: pinnedPosition.x - scroll.x
						};

						if (supportsPositionFixed && !forceScroll) {
							this.setStyle('position', 'fixed').setStyles(currentPosition);
						} else {
							parent = this.getOffsetParent();
							var position = this.getPosition(parent),
									styles = this.getStyles('left', 'top');

							if (parent && styles.left == 'auto' || styles.top == 'auto') {
								this.setPosition(position);
							}
							if (this.getStyle('position') == 'static') {
								this.setStyle('position', 'absolute');
							}

							position = {
								x: styles.left.toInt() - scroll.x,
								y: styles.top.toInt() - scroll.y
							};

							scrollFixer = function () {
								if (!this.retrieve('pin:_pinned')) { return; }
								var scroll = window.getScroll();
								this.setStyles({
									left: position.x + scroll.x,
									top: position.y + scroll.y
								});
							} .bind(this);

							this.store('pin:_scrollFixer', scrollFixer);
							window.addEvent('scroll', scrollFixer);
						}
						this.store('pin:_pinned', true);
					}

				} else {
					if (!this.retrieve('pin:_pinned')) { return this; }

					parent = this.getParent();
					var offsetParent = (parent.getComputedStyle('position') != 'static' ? parent : parent.getOffsetParent());

					pinnedPosition = this.getPosition(offsetParent);

					this.store('pin:_pinned', false);
					scrollFixer = this.retrieve('pin:_scrollFixer');
					if (!scrollFixer) {
						this.setStyles({
							position: 'absolute',
							top: pinnedPosition.y + scroll.y,
							left: pinnedPosition.x + scroll.x
						});
					} else {
						this.store('pin:_scrollFixer', null);
						window.removeEvent('scroll', scrollFixer);
					}
					this.removeClass('isPinned');
				}
				return this;
			},

			unpin: function () {
				return this.pin(false);
			},

			togglePin: function () {
				return this.pin(!this.retrieve('pin:_pinned'));
			}

		});

	})();

	// #endregion

	// #region -- Element.Position --

	/**
	* name: Element.Position
	* 
	* description: Extends the Element native object to include methods useful positioning elements relative to others.
	* 
	* authors:
	* - Aaron Newton
	* - Jacob Thornton
	* 
	* requires:
	* - Core/Options
	* - Core/Element.Dimensions
	* - Element.Measure
	* 
	* provides: [Element.Position]
	**/

	(function (original) {

		var local = Element.Position = {

			options: {/*
				edge: false,
				returnPos: false,
				minimum: {x: 0, y: 0},
				maximum: {x: 0, y: 0},
				relFixedPosition: false,
				ignoreMargins: false,
				ignoreScroll: false,
				allowNegative: false,*/
				relativeTo: document.body,
				position: {
					x: 'center', //left, center, right
					y: 'center' //top, center, bottom
				},
				offset: { x: 0, y: 0 }
			},

			getOptions: function (element, options) {
				options = Object.merge({}, local.options, options);
				local.setPositionOption(options);
				local.setEdgeOption(options);
				local.setOffsetOption(element, options);
				local.setDimensionsOption(element, options);
				return options;
			},

			setPositionOption: function (options) {
				options.position = local.getCoordinateFromValue(options.position);
			},

			setEdgeOption: function (options) {
				var edgeOption = local.getCoordinateFromValue(options.edge),
						$_op = options.position; // # 苦苦的苦瓜 2011-10-08
				options.edge = edgeOption ? edgeOption :
					($_op.x == 'center' && $_op.y == 'center') ? { x: 'center', y: 'center'} : { x: 'left', y: 'top' };
			},

			setOffsetOption: function (element, options) {
				var parentOffset = { x: 0, y: 0 },
						$_docID = document.id, // # 苦苦的苦瓜 2011-10-08
						offsetParent = element.measure(function () {
							return $_docID(this.getOffsetParent());
						}),
						parentScroll = offsetParent.getScroll();

				if (!offsetParent || offsetParent == element.getDocument().body) {
					return;
				}
				parentOffset = offsetParent.measure(function () {
					var position = this.getPosition();
					if (this.getStyle('position') == 'fixed') {
						var scroll = window.getScroll();
						position.x += scroll.x;
						position.y += scroll.y;
					}
					return position;
				});

				options.offset = {
					parentPositioned: offsetParent != $_docID(options.relativeTo),
					x: options.offset.x - parentOffset.x + parentScroll.x,
					y: options.offset.y - parentOffset.y + parentScroll.y
				};
			},

			setDimensionsOption: function (element, options) {
				options.dimensions = element.getDimensions({
					computeSize: true,
					styles: ['padding', 'border', 'margin']
				});
			},

			getPosition: function (element, options) {
				var position = {},
						$_doc = document,
						$_ceil = Math.ceil; // # 苦苦的苦瓜 2011-10-08
				options = local.getOptions(element, options);
				var relativeTo = $_doc.id(options.relativeTo) || $_doc.body;

				local.setPositionCoordinates(options, position, relativeTo);
				if (options.edge) {
					local.toEdge(position, options);
				}

				var offset = options.offset,
						$_x = position.x,
						$_y = position.y,
						$_op = offset.parentPositioned,
						$_oa = options.allowNegative; // # 苦苦的苦瓜 2011-10-08
				position.left = (($_x >= 0 || $_op || $_oa) ? $_x : 0).toInt();
				position.top = (($_y >= 0 || $_op || $_oa) ? $_y : 0).toInt();

				local.toMinMax(position, options);

				if (options.relFixedPosition || relativeTo.getStyle('position') == 'fixed') {
					local.toRelFixedPosition(relativeTo, position);
				}
				if (options.ignoreScroll) {
					local.toIgnoreScroll(relativeTo, position);
				}
				if (options.ignoreMargins) {
					local.toIgnoreMargins(position, options);
				}

				position.left = $_ceil(position.left);
				position.top = $_ceil(position.top);
				delete position.x;
				delete position.y;

				return position;
			},

			setPositionCoordinates: function (options, position, relativeTo) {
				var $_body = document.body, $_win = window, $_oo = options.offset, $_op = options.position, // # 苦苦的苦瓜 2011-10-08
						offsetY = $_oo.y,
						offsetX = $_oo.x,
						calc = (relativeTo == $_body) ? $_win.getScroll() : relativeTo.getPosition(),
						top = calc.y,
						left = calc.x,
						winSize = $_win.getSize();

				switch ($_op.x) {
					case 'left':
						position.x = left + offsetX;
						break;

					case 'right':
						position.x = left + offsetX + relativeTo.offsetWidth;
						break;

					default:
						position.x = left + ((relativeTo == $_body ? winSize.x : relativeTo.offsetWidth) / 2) + offsetX;
						break;
				}

				switch ($_op.y) {
					case 'top':
						position.y = top + offsetY;
						break;

					case 'bottom':
						position.y = top + offsetY + relativeTo.offsetHeight;
						break;

					default:
						position.y = top + ((relativeTo == $_body ? winSize.y : relativeTo.offsetHeight) / 2) + offsetY;
						break;
				}
			},

			toMinMax: function (position, options) {
				var xy = { left: 'x', top: 'y' }, value;
				['minimum', 'maximum'].each(function (minmax) {
					['left', 'top'].each(function (lr) {
						value = options[minmax] ? options[minmax][xy[lr]] : null;
						if (value != null && ((minmax == 'minimum') ? position[lr] < value : position[lr] > value)) {
							position[lr] = value;
						}
					});
				});
			},

			toRelFixedPosition: function (relativeTo, position) {
				var winScroll = window.getScroll();
				position.top += winScroll.y;
				position.left += winScroll.x;
			},

			toIgnoreScroll: function (relativeTo, position) {
				var relScroll = relativeTo.getScroll();
				position.top -= relScroll.y;
				position.left -= relScroll.x;
			},

			toIgnoreMargins: function (position, options) {
				position.left += options.edge.x == 'right'
				? options.dimensions['margin-right']
				: (options.edge.x != 'center'
					? -options.dimensions['margin-left']
					: -options.dimensions['margin-left'] + ((options.dimensions['margin-right'] + options.dimensions['margin-left']) / 2));

				position.top += options.edge.y == 'bottom'
				? options.dimensions['margin-bottom']
				: (options.edge.y != 'center'
					? -options.dimensions['margin-top']
					: -options.dimensions['margin-top'] + ((options.dimensions['margin-bottom'] + options.dimensions['margin-top']) / 2));
			},

			toEdge: function (position, options) {
				var edgeOffset = {},
						dimensions = options.dimensions,
						edge = options.edge;

				switch (edge.x) {
					case 'left':
						edgeOffset.x = 0;
						break;

					case 'right':
						edgeOffset.x = -dimensions.x - dimensions.computedRight - dimensions.computedLeft;
						break;

					default: // center
						edgeOffset.x = -(Math.round(dimensions.totalWidth / 2));
						break;
				}

				switch (edge.y) {
					case 'top':
						edgeOffset.y = 0;
						break;

					case 'bottom':
						edgeOffset.y = -dimensions.y - dimensions.computedTop - dimensions.computedBottom;
						break;

					default: // center
						edgeOffset.y = -(Math.round(dimensions.totalHeight / 2));
						break;
				}

				position.x += edgeOffset.x;
				position.y += edgeOffset.y;
			},

			getCoordinateFromValue: function (option) {
				if (typeOf(option) != 'string') { return option; }
				option = option.toLowerCase();

				return {
					x: option.test('left') ? 'left' : (option.test('right') ? 'right' : 'center'),
					y: option.test(/upper|top/) ? 'top' : (option.test('bottom') ? 'bottom' : 'center')
				};
			}

		};

		Element.implement({

			position: function (options) {
				if (options && (options.x != null || options.y != null)) {
					return (original ? original.apply(this, arguments) : this);
				}
				var position = this.setStyle('position', 'absolute').calculatePosition(options);
				return (options && options.returnPos) ? position : this.setStyles(position);
			},

			calculatePosition: function (options) {
				return local.getPosition(this, options);
			}

		});

	})(Element.prototype.position);

	// #endregion

	// #region -- Element.Shortcuts --

	/**
	* name: Element.Shortcuts
	* 
	* description: Extends the Element native object to include some shortcut methods.
	* 
	* authors:
	*		- Aaron Newton
	* 
	* requires:
	*		- Core/Element.Style
	*		- /MooTools.More
	* 
	* provides: [Element.Shortcuts]
	**/

	Element.implement({

		isDisplayed: function () {
			return this.getStyle('display') != 'none';
		},

		isVisible: function () {
			var w = this.offsetWidth,
					h = this.offsetHeight;
			return (w == 0 && h == 0) ? false : (w > 0 && h > 0) ? true : this.style.display != 'none';
		},

		toggle: function () {
			return this[this.isDisplayed() ? 'hide' : 'show']();
		},

		hide: function () {
			var d;
			try {
				//IE fails here if the element is not in the dom
				d = this.getStyle('display');
			} catch (e) { }
			if (d == 'none') { return this; }
			return this.store('element:_originalDisplay', d || '').setStyle('display', 'none');
		},

		show: function (display) {
			if (!display && this.isDisplayed()) { return this; }
			display = display || this.retrieve('element:_originalDisplay') || 'block';
			return this.setStyle('display', (display == 'none') ? 'block' : display);
		},

		swapClass: function (remove, add) {
			return this.removeClass(remove).addClass(add);
		}

	});

	Document.implement({

		clearSelection: function () {
			var $_doc = document, $_win = window; // # 苦苦的苦瓜 2011-10-08
			if ($_win.getSelection) {
				var selection = $_win.getSelection();
				if (selection && selection.removeAllRanges) {
					selection.removeAllRanges();
				}
			} else if ($_doc.selection && $_doc.selection.empty) {
				try {
					//IE fails here if selected element is not in dom
					$_doc.selection.empty();
				} catch (e) { }
			}
		}

	});

	// #endregion

	// #region -- Drag --

	/**
	* name: Drag
	* 
	* description: The base Drag Class. Can be used to drag and resize Elements using mouse events.
	* 
	* authors:
	*		- Valerio Proietti
	*		- Tom Occhinno
	*		- Jan Kassens
	* 
	* requires:
	*		- Core/Events
	*		- Core/Options
	*		- Core/Element.Event
	*		- Core/Element.Style
	*		- Core/Element.Dimensions
	*		- /MooTools.More
	* 
	* provides: [Drag]
	**/

	// UI插件, 拖动/缩放基类
	// 参考我佛山人关于mootools1.2-Drag的源码分析(http://space.flash8.net/space/?18713/viewspace-408445.html)
	var Drag = this.Drag = new Class({

		// 继承自Events和Options,UI组件的基本要求:事件支持及属性可选
		Implements: [Events, Options],

		options: {/*
		// 开始拖动前事件
		onBeforeStart: function(thisElement){},
		// 开始拖动事件
		onStart: function(thisElement, event){},
		onSnap: function(thisElement){},
		// 拖动事件
		onDrag: function(thisElement, event){},
		// 取消拖动事件
		onCancel: function(thisElement){},
		// 拖动完成事件
		onComplete: function(thisElement, event){},*/
			// 自动吸附距离
			snap: 6,
			// 单位
			unit: 'px',
			// 网格大小
			grid: false,
			// 指定是否CSS属性
			style: true,
			// 拖动范围限制
			limit: false,
			// 可拖动的句柄
			handle: false,
			// 反转
			invert: false,
			preventDefault: false,
			stopPropagation: false,
			// 鼠标拖动时对象改变的样式属性,当x,y为left和top时是移动,为width和height时为缩放
			modifiers: { x: 'left', y: 'top' }
		},

		// 构造函数
		initialize: function () {
			// Array.link对参数处理, 实现配置属性与作用对象的位置无关性
			var params = Array.link(arguments, {
				'options': Type.isObject,
				'element': function (obj) {
					return obj != null;
				}
			});

			var $_doc = document,
					$_docID = $_doc.id,
					$_isIE = Browser.ie; // # 苦苦的苦瓜 2011-10-08

			// 拖动作用的对象
			this.element = $_docID(params.element);
			// 拖动作用对象所属的文档对象
			this.document = this.element.getDocument();
			// 调用Options类的方法，实现可选参数
			this.setOptions(params.options || {});
			// 句柄参数的类型
			var htype = typeOf(this.options.handle);
			// 触发拖动的句柄, 可支持多个对象, 也可为单个, 当不提供handle参数时使用拖动作用的对象
			this.handles = ((htype == 'array' || htype == 'collection') ? $$(this.options.handle) : $_docID(this.options.handle)) || this.element;
			// 鼠标的相关值集合
			this.mouse = { 'now': {}, 'pos': {} };
			// 对象的坐标值集合
			this.value = { 'start': {}, 'now': {} };

			// 选取事件名,ie内核浏览器使用onselectstart
			this.selection = ($_isIE) ? 'selectstart' : 'mousedown';

			if ($_isIE && !Drag.ondragstartFixed) {
				$_doc.ondragstart = Function.from(false);
				Drag.ondragstartFixed = true;
			}

			// 使用闭包绑定当前对象的事件方法集
			this.bound = {
				// 开始
				start: this.start.bind(this),
				// 检查
				check: this.check.bind(this),
				// 拖动
				drag: this.drag.bind(this),
				// 停止
				stop: this.stop.bind(this),
				// 取消
				cancel: this.cancel.bind(this),
				// 停止事件冒泡
				eventStop: Function.from(false)
			};
			// 附加事件
			this.attach();
		},

		// 附加事件
		attach: function () {
			this.handles.addEvent('mousedown', this.bound.start);
			return this;
		},

		// 移除事件
		detach: function () {
			this.handles.removeEvent('mousedown', this.bound.start);
			return this;
		},

		// 开始拖动处理
		start: function (event) {
			var options = this.options,
					$_el = this.element; // # 苦苦的苦瓜 2011-10-08

			if (event.rightClick) { return; }

			if (options.preventDefault) { event.preventDefault(); }
			if (options.stopPropagation) { event.stopPropagation(); }
			// 鼠标的初始位置信息
			this.mouse.start = event.page;

			// 触发拖动前事件
			this.fireEvent('beforeStart', $_el);

			// 范围限制
			var limit = options.limit;
			this.limit = { x: [], y: [] };

			var z, coordinates,
					$_now = this.value.now, $_pos = this.mouse.pos; // # 苦苦的苦瓜 2011-10-08
			// 遍历作用的属性名
			for (z in options.modifiers) {
				var $_item = options.modifiers[z];

				// 如果值为false,忽略
				if (!$_item) { continue; }

				// 从样式中取对应属性值
				var style = $_el.getStyle($_item);

				// Some browsers (IE and Opera) don't always return pixels.
				if (style && !style.match(/px$/)) {
					if (!coordinates) {
						coordinates = $_el.getCoordinates($_el.getOffsetParent());
					}
					style = coordinates[$_item];
				}

				// 如果指定使用样式属性,从样式中取对应属性值
				if (options.style) {
					$_now[z] = (style || 0).toInt();
				} else { // 否则从属性中取值
					$_now[z] = $_el[$_item];
				}

				// 如果指定反转,取负值(正取负,负取正)
				if (options.invert) { $_now[z] *= -1; }

				// 计算鼠标相对位置
				$_pos[z] = event.page[z] - $_now[z];

				// 如果指定相应方向上的范围限制
				if (limit && limit[z]) {
					var i = 2;
					while (i--) {
						var limitZI = limit[z][i];
						if (limitZI || limitZI === 0) {
							this.limit[z][i] = (typeof limitZI == 'function') ? limitZI() : limitZI;
						}
					}
				}
			}

			var $_grid = this.options.grid,
					$_bound = this.bound; // # 苦苦的苦瓜 2011-10-08

			// 网格方式的移动/缩放
			if (typeOf($_grid) == 'number') {
				this.options.grid = {
					x: $_grid,
					y: $_grid
				};
			}

			var events = {
				mousemove: $_bound.check,
				mouseup: $_bound.cancel
			};
			// 屏蔽当前文档的选择
			events[this.selection] = $_bound.eventStop;
			// 监听当前文档的鼠标移动和弹起事件
			this.document.addEvents(events);
		},

		// 检查条件约束
		check: function (event) {
			var $_options = this.options,
					$_page = event.page,
					$_start = this.mouse.start; // # 苦苦的苦瓜 2011-10-08
			if ($_options.preventDefault) { event.preventDefault(); }
			// 计算当前鼠标移动的距离
			var distance = Math.round(Math.sqrt(Math.pow($_page.x - $_start.x, 2) + Math.pow($_page.y - $_start.y, 2)));
			// 如果超出吸附距离
			if (distance > $_options.snap) {
				var $_bound = this.bound,
						$_el = this.element; // # 苦苦的苦瓜 2011-10-08
				// 移除拖动前检查约束的事件监听
				this.cancel();
				// 添加拖动处理相关的事件监听
				this.document.addEvents({
					mousemove: $_bound.drag,
					mouseup: $_bound.stop
				});
				// 触发Start和Snap事件
				this.fireEvent('start', [$_el, event]).fireEvent('snap', $_el);
			}
		},

		// 拖动
		drag: function (event) {
			var options = this.options,
					$_mouse = this.mouse,
					$_mp = $_mouse.pos,
					$_vn = this.value.now,
					$_limit = this.limit,
					$_el = this.element; // # 苦苦的苦瓜 2011-10-08

			if (options.preventDefault) { event.preventDefault(); }
			// 当前鼠标坐标
			$_mouse.now = event.page;
			var _mn = $_mouse.now;

			// 遍历拖动作用的属性
			for (var z in options.modifiers) {
				var $_item = options.modifiers[z]; // # 苦苦的苦瓜 2011-10-08

				// 如果值为false,忽略该属性
				if (!$_item) { continue; }
				// 计算当前值
				$_vn[z] = _mn[z] - $_mp[z];

				// 反转值
				if (options.invert) { $_vn[z] *= -1; }

				// 范围限制处理
				if (options.limit && $_limit[z]) {
					var $_lz0 = $_limit[z][0]; // # 苦苦的苦瓜 2011-10-08
					var $_lz1 = $_limit[z][1]; // # 苦苦的苦瓜 2011-10-08
					// 如果当前方向上的值大于上限
					if (($_lz1 || $_lz1 === 0) && ($_vn[z] > $_lz1)) {
						// 取上限值
						$_vn[z] = $_lz1;
						// 如果当前值小于下限
					} else if (($_lz0 || $_lz0 === 0) && ($_vn[z] < $_lz0)) {
						// 取下限值
						$_vn[z] = $_lz0;
					}
				}

				// 相对于网格大小取值
				if (options.grid[z]) {
					$_vn[z] -= (($_vn[z] - ($_limit[z][0] || 0)) % options.grid[z]);
				}

				// 根据指定样式还是属性的值设置
				if (options.style) {
					$_el.setStyle($_item, $_vn[z] + options.unit);
				} else {
					$_el[$_item] = $_vn[z];
				}
			}

			// 触发Drag事件
			this.fireEvent('drag', [$_el, event]);
		},

		// 取消
		cancel: function (event) {
			// 移除事件监听
			this.document.removeEvents({
				mousemove: this.bound.check,
				mouseup: this.bound.cancel
			});
			if (event) {
				this.document.removeEvent(this.selection, this.bound.eventStop);
				// 触发Cancel事件
				this.fireEvent('cancel', this.element);
			}
		},

		// 停止, 打扫战场
		stop: function (event) {
			var events = {
				mousemove: this.bound.drag,
				mouseup: this.bound.stop
			};
			events[this.selection] = this.bound.eventStop;
			// 移除各事件
			this.document.removeEvents(events);
			// 触发onComplete事件
			if (event) this.fireEvent('complete', [this.element, event]);
		}

	});

	// 根据Drag为Element扩展功能
	Element.implement({

		// 使当前对象可缩放
		makeResizable: function (options) {
			var drag = new Drag(this, Object.merge({
				modifiers: {
					x: 'width',
					y: 'height'
				}
			}, options));

			this.store('resizer', drag);
			return drag.addEvent('drag', function () {
				this.fireEvent('resize', drag);
			} .bind(this));
		}

	});

	// #endregion

	// #region -- Drag.Move --

	/**
	* name: Drag.Move
	* 
	* description: A Drag extension that provides support for the constraining of draggables to containers and droppables.
	* 
	* authors:
	*		- Valerio Proietti
	*		- Tom Occhinno
	*		- Jan Kassens
	*		- Aaron Newton
	*		- Scott Kyle
	* 
	* requires:
	*		- Core/Element.Dimensions
	*		- /Drag
	* 
	* provides: [Drag.Move]
	**/

	// 拖放类
	// 参考我佛山人关于mootools1.2-Drag的源码分析(http://space.flash8.net/space/?18713/viewspace-408713.html)
	Drag.Move = new Class({

		// 继承自Drag类
		Extends: Drag,

		options: {/*
		onEnter: function(thisElement, overed){},
		onLeave: function(thisElement, overed){},
		onDrop: function(thisElement, overed, event){},*/
			// 可以用于放落的对象数组
			droppables: [],
			// 限制拖动范围的容器
			container: false,
			precalculate: false,
			includeMargins: true,
			checkDroppables: true
		},

		// 构造函数
		initialize: function (element, options) {
			// 调用父类同名方法
			this.parent(element, options);
			element = this.element;

			var $_options = this.options,
					$_docID = document.id; // # 苦苦的苦瓜 2011-10-08

			// 获取可以用于放落的对象集合
			this.droppables = $$($_options.droppables);
			this.container = $_docID($_options.container);

			var $_container = this.container; // # 苦苦的苦瓜 2011-10-08

			if ($_container && typeOf($_container) != 'element') {
				this.container = $_docID($_container.getDocument().body);
			}

			if ($_options.style) {
				var $_modifiers = $_options.modifiers; // # 苦苦的苦瓜 2011-10-08
				if ($_modifiers.x == 'left' && $_modifiers.y == 'top') {
					var parent = element.getOffsetParent(),
					styles = element.getStyles('left', 'top');
					if (parent && (styles.left == 'auto' || styles.top == 'auto')) {
						element.setPosition(element.getPosition(parent));
					}
				}

				// 如果为默认的静态定位, 改为绝对定位
				if (element.getStyle('position') == 'static') {
					element.setStyle('position', 'absolute');
				}
			}

			// 添加onStart事件监听, 用addEvent的第三个参数指定为内部事件, 可免于被移除
			this.addEvent('start', this.checkDroppables, true);
			this.overed = null;
		},

		// 开始拖动, 将覆盖父类Drag的同名方法
		start: function (event) {
			// 如果指定容器
			if (this.container) {
				this.options.limit = this.calculateLimit();
			}

			if (this.options.precalculate) {
				this.positions = this.droppables.map(function (el) {
					return el.getCoordinates();
				});
			}

			this.parent(event);
		},

		calculateLimit: function () {
			var element = this.element,
					container = this.container,

					$_doc = document, // # 苦苦的苦瓜 2011-10-08

					offsetParent = $_doc.id(element.getOffsetParent()) || $_doc.body,
					containerCoordinates = container.getCoordinates(offsetParent),
					elementMargin = {},
					elementBorder = {},
					containerMargin = {},
					containerBorder = {},
					offsetParentPadding = {};

			// 取padding和margin在四个方向上的值
			['top', 'right', 'bottom', 'left'].each(function (pad) {
				elementMargin[pad] = element.getStyle('margin-' + pad).toInt();
				elementBorder[pad] = element.getStyle('border-' + pad).toInt();
				containerMargin[pad] = container.getStyle('margin-' + pad).toInt();
				containerBorder[pad] = container.getStyle('border-' + pad).toInt();
				offsetParentPadding[pad] = offsetParent.getStyle('padding-' + pad).toInt();
			}, this);

			// 得到真实尺寸
			var width = element.offsetWidth + elementMargin.left + elementMargin.right,
					height = element.offsetHeight + elementMargin.top + elementMargin.bottom,
					left = 0,
					top = 0,
					right = containerCoordinates.right - containerBorder.right - width,
					bottom = containerCoordinates.bottom - containerBorder.bottom - height;

			if (this.options.includeMargins) {
				left += elementMargin.left;
				top += elementMargin.top;
			} else {
				right += elementMargin.right;
				bottom += elementMargin.bottom;
			}

			if (element.getStyle('position') == 'relative') {
				var coords = element.getCoordinates(offsetParent);
				coords.left -= element.getStyle('left').toInt();
				coords.top -= element.getStyle('top').toInt();

				left -= coords.left;
				top -= coords.top;
				if (container.getStyle('position') != 'relative') {
					left += containerBorder.left;
					top += containerBorder.top;
				}
				right += elementMargin.left - coords.left;
				bottom += elementMargin.top - coords.top;

				if (container != offsetParent) {
					left += containerMargin.left + offsetParentPadding.left;
					var $_bw = Browser; // # 苦苦的苦瓜 2011-10-08
					top += (($_bw.ie6 || $_bw.ie7) ? 0 : containerMargin.top) + offsetParentPadding.top;
				}
			} else {
				left -= elementMargin.left;
				top -= elementMargin.top;
				if (container != offsetParent) {
					left += containerCoordinates.left + containerBorder.left;
					top += containerCoordinates.top + containerBorder.top;
				}
			}

			return {
				x: [left, right],
				y: [top, bottom]
			};
		},

		getDroppableCoordinates: function (element) {
			var position = element.getCoordinates();
			if (element.getStyle('position') == 'fixed') {
				var scroll = window.getScroll();
				position.left += scroll.x;
				position.right += scroll.x;
				position.top += scroll.y;
				position.bottom += scroll.y;
			}
			return position;
		},

		checkDroppables: function () {
			var overed = this.droppables.filter(function (el, i) {
				el = this.positions ? this.positions[i] : this.getDroppableCoordinates(el);
				var now = this.mouse.now;
				return (now.x > el.left && now.x < el.right && now.y < el.bottom && now.y > el.top);
			}, this).getLast();

			if (this.overed != overed) {
				if (this.overed) {
					this.fireEvent('leave', [this.element, this.overed]);
				}
				if (overed) {
					this.fireEvent('enter', [this.element, overed]);
				}
				this.overed = overed;
			}
		},

		// 拖动, 将覆盖父类同名方法
		drag: function (event) {
			// 调用父类同名方法
			this.parent(event);
			// 如果可放落对象数组不为空, 在每次移动时检查碰撞
			if (this.options.checkDroppables && this.droppables.length) {
				this.checkDroppables();
			}
		},

		// 停止拖动, 将覆盖父类同名方法
		stop: function (event) {
			// 在松开鼠标时再次检查碰撞
			this.checkDroppables();
			// 触发onDrop放落事件
			this.fireEvent('drop', [this.element, this.overed, event]);
			// 置空
			this.overed = null;
			// 调用父类同名方法
			return this.parent(event);
		}

	});

	// 根据Drag.Move对Element的扩展实现
	Element.implement({

		// 使对象可拖放化
		makeDraggable: function (options) {
			var drag = new Drag.Move(this, options);
			this.store('dragger', drag);
			return drag;
		}

	});

	// #endregion

	// #region -- Slider --

	/**
	* name: Slider
	* 
	* description: Class for creating horizontal and vertical slider controls.
	* 
	* authors:
	*		- Valerio Proietti
	* 
	* requires:
	*		- Core/Element.Dimensions
	*		- /Class.Binds
	*		- /Drag
	*		- /Element.Measure
	* 
	* provides: [Slider]
	**/

	// 滑动条
	var Slider = this.Slider = new Class({

		Implements: [Events, Options],

		Binds: ['clickedElement', 'draggedKnob', 'scrolledElement'],

		options: {/*
		onTick: function(intPosition){},
		// 位置改变事件
		onChange: function(intStep){},
		// 拖动改变位置完成事件
		onComplete: function(strStep){},*/
			// 每一步的事件
			onTick: function (position) {
				this.setKnobPosition(position);
			},
			initialStep: 0,
			snap: false,
			// 偏移量
			offset: 0,
			// 指定滑动范围
			range: false,
			// 滚轮支持
			wheel: false,
			// 总步数
			steps: 100,
			// 滑动模式, 水平或纵向
			mode: 'horizontal'
		},

		// 构造函数, 需要三个参数
		// element为滑块所在容器, knob为滑块
		initialize: function (element, knob, options) {
			// 合并参数
			this.setOptions(options);
			options = this.options;
			// 取滑块所在的容器对象
			this.element = document.id(element);
			// 滑块
			knob = this.knob = document.id(knob);
			// 初始化位置标记变量
			this.previousChange = this.previousEnd = this.step = -1;

			// 初始化
			var limit = {},
					modifiers = { x: false, y: false };

			// 根据不同滑动模式初始化变量值
			switch (options.mode) {
				case 'vertical': // 纵向滑动时
					// 别名为y轴方向
					this.axis = 'y';
					// 这时主要是需要改变滑块CSS属性中的top
					this.property = 'top';
					// 此时需要取值的属性为offsetHeiht
					this.offset = 'offsetHeight';
					break;

				case 'horizontal': // 横向滑动时
					// 别名为x轴方向
					this.axis = 'x';
					// 这时主要是需要改变滑块CSS属性中的left
					this.property = 'left';
					// 此时需要取值的属性为offsetWidth
					this.offset = 'offsetWidth';
			}

			this.setSliderDimensions();
			this.setRange(options.range);

			// 
			if (knob.getStyle('position') == 'static') {
				knob.setStyle('position', 'relative');
			}
			// 滑块相对于容器为相对定位
			knob.setStyle(this.property, -options.offset);
			// 当前方向上对应的属性,转化用于Drag类的参数
			modifiers[this.axis] = this.property;
			// 滑块的坐标范围
			limit[this.axis] = [-options.offset, this.full - options.offset];

			var dragOptions = {
				snap: 0,
				// 滑块的可拖动范围
				limit: limit,
				modifiers: modifiers,
				onDrag: this.draggedKnob,
				onStart: this.draggedKnob,
				onBeforeStart: (function () {
					this.isDragging = true;
				}).bind(this),
				onCancel: function () {
					this.isDragging = false;
				} .bind(this),
				onComplete: function () {
					this.isDragging = false;
					this.draggedKnob();
					this.end();
				} .bind(this)
			};
			// 如果指定吸附值
			if (options.snap) {
				this.setSnap(dragOptions);
			}

			// 使滑块可拖动
			this.drag = new Drag(knob, dragOptions);
			this.attach();
			if (options.initialStep != null) {
				this.set(options.initialStep);
			}
		},

		attach: function () {
			// 添加鼠标按下的事件监听, 实现点击时自动滑到指定位置
			this.element.addEvent('mousedown', this.clickedElement);
			// 如果设置支持滚轮, 为容器添加滚轮监听事件
			if (this.options.wheel) {
				this.element.addEvent('mousewheel', this.scrolledElement);
			}
			this.drag.attach();
			return this;
		},

		detach: function () {
			this.element.removeEvent('mousedown', this.clickedElement).removeEvent('mousewheel', this.scrolledElement);
			this.drag.detach();
			return this;
		},

		autosize: function () {
			this.setSliderDimensions().setKnobPosition(this.toPosition(this.step));
			this.drag.options.limit[this.axis] = [-this.options.offset, this.full - this.options.offset];
			if (this.options.snap) { this.setSnap(); }
			return this;
		},

		setSnap: function (options) {
			if (!options) {
				options = this.drag.options;
			}
			// 滑块拖动将网格化,单元格边长为滑动每一步所占的宽度
			options.grid = Math.ceil(this.stepWidth);
			// 改变移动范围的上限,此时忽略偏移量
			options.limit[this.axis][1] = this.full;
			return this;
		},

		setKnobPosition: function (position) {
			// 如果指定吸附, 根据步数计算位置
			if (this.options.snap) {
				position = this.toPosition(this.step);
			}
			// 设置滑块的位置
			this.knob.setStyle(this.property, position);
			return this;
		},

		setSliderDimensions: function () {
			// 计算滑块移动的总距离
			this.full = this.element.measure(function () {
				// 取滑块在当前滑动方向上的尺寸的一半
				this.half = this.knob[this.offset] / 2;
				return this.element[this.offset] - this.knob[this.offset] + (this.options.offset * 2);
			} .bind(this));
			return this;
		},

		// 设置值
		set: function (step) {
			// 当范围上下限从小到大并且当前步值小于下限, 或当范围上下限从大到小并且当前步值大于下限时, 设置步值为下限值
			if (!((this.range > 0) ^ (step < this.min))) {
				step = this.min;
			}
			// 当范围上下限从小到大并且当前步值大于是限, 或当范围上下限从大到小并且当前步值小于上限时, 设置步值为上限值
			if (!((this.range > 0) ^ (step > this.max))) {
				step = this.max;
			}

			// 计算步数
			this.step = Math.round(step);
			// 检查步数变化，以决定是否触发事件；触发步进事件；结束滑动
			return this.checkStep().fireEvent('tick', this.toPosition(this.step)).end();
		},

		setRange: function (range, pos) {
			// 取范围的下限, 默认为0
			this.min = Array.pick([range[0], 0]);
			// 取范围的上限, 默认为滑动的总步数
			this.max = Array.pick([range[1], this.options.steps]);
			// 计算范围值
			this.range = this.max - this.min;
			// 总步数, 如果steps参数值为0, 则设为滑块移动的总距离
			this.steps = this.options.steps || this.full;
			// 计算每滑动一步的距离
			this.stepSize = Math.abs(this.range) / this.steps;
			// 计算每一步所占的宽度(根据上面的等级,这里不如直接用this.stepWidth = this.full/this.steps)
			this.stepWidth = this.stepSize * this.full / Math.abs(this.range);
			if (range) {
				this.set(Array.pick([pos, this.step]).floor(this.min).max(this.max));
			}
			return this;
		},

		// 点击直接跳到指定位置
		clickedElement: function (event) {
			if (this.isDragging || event.target == this.knob) {
				return;
			}

			// 判断方向
			var dir = this.range < 0 ? -1 : 1,
			// 取当前模式下的鼠标在容器内的偏移值
					position = event.page[this.axis] - this.element.getPosition()[this.axis] - this.half;

			// 边界处理
			position = position.limit(-this.options.offset, this.full - this.options.offset);

			// 计算步数
			this.step = Math.round(this.min + dir * this.toStep(position));

			// 检查步数变化, 以决定是否触发事件；触发步进事件；结束滑动
			this.checkStep().fireEvent('tick', position).end();
		},

		// 利用滚轮跳到指定位置
		scrolledElement: function (event) {
			// 横向滑动和纵向滑动时,滚轮前滚和后滚导致的滑块的变化方向相反
			var mode = (this.options.mode == 'horizontal') ? (event.wheel < 0) : (event.wheel > 0);
			// mode为真是向小值(左上)滑动, 返之向大值(右下)滑动
			this.set(this.step + (mode ? -1 : 1) * this.stepSize);
			// 阻止事件冒泡及返回值
			event.stop();
		},

		// 滑块移动时的处理
		draggedKnob: function () {
			// 判断方向
			var dir = this.range < 0 ? -1 : 1,
			// 取当前模式下的鼠标坐标值
					position = this.drag.value.now[this.axis];

			// 边界处理
			position = position.limit(-this.options.offset, this.full - this.options.offset);

			// 计算当前的步数
			this.step = Math.round(this.min + dir * this.toStep(position));
			// 检查滑动位置有无变化
			this.checkStep();
		},

		// 检查步数有无变化
		checkStep: function () {
			var step = this.step;
			// 两值不等说明有改变
			if (this.previousChange != step) {
				// 更新旧值
				this.previousChange = step;
				// 触发onChange事件, 传送当前步数作参数
				this.fireEvent('change', step);
			}
			return this;
		},

		// 结束滑动, 检查步数有无变化
		end: function () {
			var step = this.step;
			// 两值不等说明有改变
			if (this.previousEnd !== step) {
				// 更新旧值
				this.previousEnd = step;
				// 触发onComplete事件, 传送当前步数作参数
				this.fireEvent('complete', step + '');
			}
			return this;
		},

		// 根据鼠标位置计算当前的步数
		toStep: function (position) {
			var step = (position + this.options.offset) * this.stepSize / this.full * this.steps;
			return this.options.steps ? Math.round(step -= step % this.stepSize) : step;
		},

		// 根据当前的步数计算滑块的位置
		toPosition: function (step) {
			return (this.full * Math.abs(this.min - step)) / (this.steps * this.stepSize) - this.options.offset;
		}

	});

	// #endregion

	// #region -- Assets --

	/**
	* name: Assets
	* 
	* description: Provides methods to dynamically load JavaScript, CSS, and Image files into the document.
	* 
	* authors:
	*		- Valerio Proietti
	* 
	* requires:
	*		- Core/Element.Event
	*		- /MooTools.More
	* 
	* provides: [Assets]
	**/

	// 脚本、样式和图片的资源加载
	var Asset = this.Asset = {

		// JS脚本资源的加载
		javascript: function (source, properties) {
			if (!properties) { properties = {}; }

			// 创建scrīpt Element, 指定路径及脚本类型
			var script = new Element('script', { src: source, type: 'text/javascript' }),
					doc = properties.document || document,
					load = properties.onload || properties.onLoad;

			// 删除非scrīpt标签的属性
			delete properties.onload;
			delete properties.onLoad;
			delete properties.document;

			// 添加事件监听
			if (load) {
				if (typeof script.onreadystatechange != 'undefined') {
					// 加载状态更改事件
					script.addEvent('readystatechange', function () {
						// 如果状态码为loaded或complete中的一种, 表明加载完成
						if (['loaded', 'complete'].contains(this.readyState)) {
							load.call(this);
						}
					});
				} else {
					// 加载完成事件
					script.addEvent('load', load);
				}
			}

			// 设置标签属性
			return script.set(properties).inject(doc.head);
		},

		// 样式资源的加载
		css: function (source, properties) {
			if (!properties) { properties = {}; }

			// 创建link Element, 设置属性并插入到当前文档头部
			var link = new Element('link', {
				rel: 'stylesheet',
				media: 'screen',
				type: 'text/css',
				href: source
			});

			var load = properties.onload || properties.onLoad,
					doc = properties.document || document;

			delete properties.onload;
			delete properties.onLoad;
			delete properties.document;

			if (load) { link.addEvent('load', load); }
			return link.set(properties).inject(doc.head);
		},

		// 图片资源的加载
		image: function (source, properties) {
			if (!properties) { properties = {}; }

			// 创建Image对象
			var image = new Image(),
			// 如果Image对象无法Element化, 创建img Element
					element = document.id(image) || new Element('img');

			// 遍历处理load、abort和error事件
			['load', 'abort', 'error'].each(function (name) {
				// 为当前事件加上on前缀
				var type = 'on' + name,
						cap = 'on' + name.capitalize(),
						event = properties[type] || properties[cap] || function () { }; // 从属性集中读取事件

				// 删除属性集中的事件成员
				delete properties[cap];
				delete properties[type];

				// 为image对象绑定事件
				image[type] = function () {
					// 如果对象不存在, 退出
					if (!image) { return; }
					// 如果存在父节点
					if (!element.parentNode) {
						// 设置宽度
						element.width = image.width;
						// 设置高度
						element.height = image.height;
					}
					// 销毁对象及事件
					image = image.onload = image.onabort = image.onerror = null;
					// 延时执行事件
					event.delay(1, element, element);
					// 延时触发事件
					element.fireEvent(name, element, 1);
				};
			});

			// 设置图片路径
			image.src = element.src = source;
			// 如果图片加载完成, 延时执行onload事件
			if (image && image.complete) { image.onload.delay(1); }
			// 设置img标签属性并返回Element的引用
			return element.set(properties);
		},

		// 批量图片加载
		images: function (sources, options) {
			// 使source数组化,以兼容只有一个图片时不传数组的情况
			sources = Array.from(sources);

			var fn = function () { },
					counter = 0; // 图片加载数量标记

			// 合并参数
			options = Object.merge({
				// 图片集加载完成
				onComplete: fn,
				// 图片集加载过程
				onProgress: fn,
				onError: fn,
				properties: {}
			}, options);

			// 遍历加载
			return new Elements(sources.map(function (source, index) {
				// 使用Asset.image加载
				return Asset.image(source, Object.append(options.properties, {

					// 添加加载完成事件监听, 以实现进度通知及加载完成通知
					onload: function () {
						// 计数器加1
						counter++;
						// 进度通知, 传送当前已加载数及当前图片的顺序索引值
						options.onProgress.call(this, counter, index, source);
						// 如果计数器与source数组长度一致, 表明全部加载完成, 调用加载完成事件通知
						if (counter == sources.length) {
							options.onComplete();
						}
					},

					onerror: function () {
						counter++;
						options.onError.call(this, counter, index, source);
						if (counter == sources.length) {
							options.onComplete();
						}
					}

				}));
			}));
		}

	};

	// #endregion

});







